Last active
August 29, 2015 14:09
-
-
Save kingpong/681a509fe518a5997dd4 to your computer and use it in GitHub Desktop.
EarthView wallpaper saver bookmarklet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This bookmarklet will let you save Google EarthView images on your Mac. | |
When you click the bookmark button, it will present a box on screen with | |
instructions for how to proceed. For now, it requires using the Terminal | |
window. Maybe I'll make a full-fledged Chrome Extension later to avoid | |
that requirement. | |
Images are filed under EarthView in your Pictures folder. | |
IMPORTANT: Although iTerm2's pasting works much faster than | |
Terminal, iTerm2 garbles the input sometimes. Terminal.app is | |
recommended for this. | |
To install: | |
1. Copy the javascript: URL below to your clipboard. | |
2. Go to Bookmarks > Bookmark Manager in Chrome. | |
3. Add a new bookmark, name it whatever you want, and paste the javascript: URL in. | |
javascript:(function()%7B(function()%20%7Bvar%20background%20%3D%20document.getElementsByClassName(%22background%22)%5B0%5D.style.backgroundImage%3Bvar%20prefix%20%3D%20%22url(data%3Aimage%2Fjpeg%3Bbase64%2C%22%3Bvar%20suffix%20%3D%20%22)%22%3Bvar%20actualPrefix%20%3D%20background.slice(0%2C%20prefix.length)%3Bvar%20actualSuffix%20%3D%20background.slice(-1%20*%20suffix.length)%3Bvar%20region%20%3D%20document.getElementsByClassName(%22content__location__region%22)%5B0%5D.innerText%3Bvar%20country%20%3D%20document.getElementsByClassName(%22content__location__country%22)%5B0%5D.innerText%3Bvar%20date%20%3D%20new%20Date()%3Bvar%20timestamp%20%3D%20date.toISOString().replace(%2F%5B-%3A%5D%2Fg%2C%20%22%22).replace(%2F%5C.%5Cd%2BZ%24%2F%2C%22%22).replace(%22T%22%2C%22_%22)%3Bvar%20dirName%20%3D%20%22%24HOME%2FPictures%2FEarthView%22%3Bvar%20locationName%20%3D%20%5Bregion%2C%20country%5D.filter(function(s)%20%7B%20return%20!!s%3B%20%7D).join(%22_%22).replace(%22%20%22%2C%22_%22)%3Bif%20(!%20locationName)%20%7BlocationName%20%3D%20%22Unknown%22%3B%7Dvar%20fileName%20%3D%20locationName%20%2B%20%22.jpg%22%3Bvar%20backupFileName%20%3D%20locationName%20%2B%20%22_%22%20%2B%20timestamp%20%2B%20%22.jpg%22%3Bif%20(actualPrefix%20!%3D%20prefix)%7Balert(%22The%20prefix%20('%22%20%2B%20actualPrefix%20%2B%20%22')%20is%20not%20as%20expected.%22)%3B%7Delse%20if%20(actualSuffix%20!%3D%20suffix)%7Balert(%22The%20suffix%20('%22%20%2B%20actualSuffix%20%2B%20%22')%20is%20not%20as%20expected.%22)%3B%7Delse%7Bvar%20padding%20%3D%202%3Bvar%20margin%20%3D%202%3Bvar%20lineSize%20%3D%2072%3Bbackground%20%3D%20background.slice(prefix.length%2C%20background.length%20-%20suffix.length%20-%201)%3Bvar%20lines%20%3D%20%5B%22%2Fbin%2Fstty%20-echo%22%2C%22%2Fbin%2Fbash%22%2C%22export%20PROMPT_COMMAND%3D%20PS1%3D%20PS2%3D.%22%2C%22%2Fbin%2Fmkdir%20-p%20%5C%22%22%20%2B%20dirName%20%2B%20%22%5C%22%22%2C%22cd%20%5C%22%22%20%2B%20dirName%20%2B%20%22%5C%22%22%2C%22fn%3D%24(echo%20'%22%20%2B%20fileName.replace(%22'%22%2C%22%5C%5C'%22)%20%2B%20%22'%20%7C%20LANG%3Den_US.UTF-8%20sed%20's%2F%5B%5E%5B%3Aalpha%3A%5D%5C%5C._%5D%2F%2Fg')%22%2C%22if%20%5B%5B%20-e%20%24fn%20%5D%5D%3B%20then%20fn%3D%24(echo%20'%22%20%2B%20backupFileName.replace(%22'%22%2C%22%5C%5C'%22)%20%2B%20%22'%20%7C%20LANG%3Den_US.UTF-8%20sed%20's%2F%5B%5E%5B%3Aalpha%3A%5D%5C%5C._%5D%2F%2Fg')%3B%20fi%22%2C%22%2Fusr%2Fbin%2Fbase64%20-D%20%3C%3C__EOF__%20%3E%20%24fn%22%5D%3Bvar%20len%20%3D%20background.length%3Bfor%20(var%20i%20%3D%200%3B%20i%20%3C%20len%3B%20i%20%2B%3D%20lineSize)%7Blines.push(background.slice(i%2C%20i%2BlineSize))%3B%7Dafter%20%3D%20%5B%22__EOF__%22%2C%22md5%3D%24(%2Fsbin%2Fmd5%20-q%20%24fn)%22%2C%22touch%20.EarthView.index%22%2C%22read%20-s%20sum%20orig%20%3C%20%3C(%2Fusr%2Fbin%2Fgrep%20%5E%24md5%20.EarthView.index)%22%2C%22if%20%5B%5B%20-n%20%24orig%20%5D%5D%3B%20then%22%2C%22%20%20eval%20%24(%2Fusr%2Fbin%2Fstat%20-s%20%24fn)%22%2C%22%20%20fn_size%3D%24st_size%22%2C%22%20%20eval%20%24(%2Fusr%2Fbin%2Fstat%20-s%20%24orig%202%3E%2Fdev%2Fnull)%22%2C%22%20%20orig_size%3D%24st_size%22%2C%22%20%20if%20%5B%5B%20%24orig_size%20%3D%20%24fn_size%20%5D%5D%3B%20then%22%2C%22%20%20%20%20echo%20Removing%20duplicate%20%24fn%20because%20%24orig%20is%20the%20same%20file%22%2C%22%20%20%20%20%2Fbin%2Frm%20-f%20%24fn%22%2C%22%20%20%20%20fn%3D%24orig%22%2C%22%20%20fi%22%2C%22fi%22%2C%22(%2Fusr%2Fbin%2Fgrep%20-v%20%5E%24md5%20.EarthView.index%3B%20echo%20%24md5%20%24fn)%20%3E%20.EarthView.index.%24%24%20%26%26%20mv%20-f%20.EarthView.index.%24%24%20.EarthView.index%22%2C%22%2Fusr%2Fbin%2Fopen%20-R%20%24fn%22%2C%22echo%22%2C%22echo%20Saved%20as%20%24fn%22%2C%22exit%22%2C%22%2Fbin%2Fstty%20echo%22%2C%22%20%22%5D%3BArray.prototype.push.apply(lines%2C%20after)%3Bvar%20removeNode%20%3D%20function(id)%20%7Bvar%20existingNode%20%3D%20document.getElementById(id)%3Bif%20(existingNode)%20%7BexistingNode.parentNode.removeChild(existingNode)%3B%7D%7D%3BremoveNode(%22SaveImageContainer%22)%3BremoveNode(%22WidthTest%22)%3Bvar%20setStyle%20%3D%20function(node%2C%20styles)%20%7Bfor%20(property%20in%20styles)%20%7Bnode.style%5Bproperty%5D%20%3D%20styles%5Bproperty%5D%3B%7D%7D%3Bvar%20contentDiv%20%3D%20document.getElementsByClassName(%22content%22)%5B0%5D%3Bvar%20testEl%20%3D%20document.createElement(%22PRE%22)%3BtestEl.id%20%3D%20%22WidthTest%22%3BsetStyle(testEl%2C%20%7B%22position%22%3A%20%22absolute%22%2C%22opacity%22%3A%20%220%22%2C%22margin%22%3A%20%220%200%22%2C%22padding%22%3A%20%220%200%22%2C%22textShadow%22%3A%20%22none%22%7D)%3BtestEl.appendChild(document.createTextNode(%22m%22))%3BcontentDiv.appendChild(testEl)%3Bvar%20emPx%20%3D%20testEl.offsetWidth%3BcontentDiv.removeChild(testEl)%3Bvar%20outerContainer%20%3D%20document.createElement(%22DIV%22)%3BouterContainer.id%20%3D%20%22SaveImageContainer%22%3BsetStyle(outerContainer%2C%20%7B%22width%22%3A%20((72%20*%20emPx)%20%2B%20(padding%20*%202%20*%20emPx))%20%2B%20%22px%22%2C%22height%22%3A%20(contentDiv.offsetHeight%20-%20(margin%20*%202%20*%20emPx))%2B%20%22px%22%2C%22margin%22%3A%20(margin%20*%20emPx)%20%2B%20%22px%20auto%22%2C%22padding%22%3A%20(padding%20*%20emPx)%20%2B%20%22px%22%2C%22textShadow%22%3A%20%22none%22%2C%22backgroundColor%22%3A%20%22rgba(102%2C102%2C102%2C0.8)%22%2CwebkitBorderRadius%3A%20%226px%22%7D)%3Bvar%20innerContainer%20%3D%20document.createElement(%22DIV%22)%3BinnerContainer.id%20%3D%20%22SaveImageInnerContainer%22%3BsetStyle(innerContainer%2C%20%7Bmargin%3A%20%220%22%2Cpadding%3A%20%220%200%22%2Coverflow%3A%20%22hidden%22%2C%22height%22%3A%20(contentDiv.offsetHeight%20-%20(margin%20*%202%20*%20emPx)%20-%20(padding%20*%202%20*%20emPx))%2B%20%22px%22%7D)%3BouterContainer.appendChild(innerContainer)%3Bvar%20button%20%3D%20document.createElement(%22BUTTON%22)%3Bbutton.onclick%20%3D%20function()%20%7Bvar%20selection%20%3D%20window.getSelection()%3Bvar%20range%20%3D%20document.createRange()%3Brange.selectNodeContents(document.getElementById(%22SaveImage%22))%3Bselection.removeAllRanges()%3Bselection.addRange(range)%3B%7D%3Bbutton.innerText%20%3D%20%22Select%20Text%22%3Bvar%20instructions%20%3D%20document.createElement(%22DIV%22)%3Binstructions.id%20%3D%20%22SaveImageInstructions%22%3BsetStyle(instructions%2C%20%7BfontFamily%3A%20%22Helvetica%20Neue%22%2CfontSize%3A%20%2214px%22%2CfontWeight%3A%20%22normal%22%2CbackgroundColor%3A%20%22rgba(0%2C0%2C0%2C0.2)%22%2Cpadding%3A%20%221em%22%2CwebkitBorderRadius%3A%20%226px%22%7D)%3Bvar%20nodes%20%3D%20%5B%221.%20Click%20%22%2C%20button%2C%20%22%20to%20select%20the%20text%20below%22%2Cdocument.createElement(%22BR%22)%2C%222.%20Cmd%2Bc%20to%20copy%20to%20your%20clipboard%22%2Cdocument.createElement(%22BR%22)%2C%223.%20Open%20Terminal%20(iTerm%20may%20not%20work)%20and%20Cmd%2Bv%20to%20paste%20(takes%20a%20couple%20minutes)%22%5D%3Bfor%20(var%20n%20in%20nodes)%20%7Bn%20%3D%20nodes%5Bn%5D%3Bif%20(typeof%20n%20%3D%3D%20%22string%22)%20n%20%3D%20document.createTextNode(n)%3Binstructions.appendChild(n)%3B%7DinnerContainer.appendChild(instructions)%3Bvar%20commandsNode%20%3D%20document.createElement(%22PRE%22)%3BcommandsNode.id%20%3D%20%22SaveImage%22%3BcommandsNode.appendChild(document.createTextNode(lines.join(%22%5Cn%22)))%3BinnerContainer.appendChild(commandsNode)%3BcontentDiv.appendChild(outerContainer)%3B%7D%7D)()%7D)() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment