Skip to content

Instantly share code, notes, and snippets.

@edo9k
Created December 16, 2020 01:30
Show Gist options
  • Save edo9k/859931cf4b01eef37283cf8ca87a9127 to your computer and use it in GitHub Desktop.
Save edo9k/859931cf4b01eef37283cf8ca87a9127 to your computer and use it in GitHub Desktop.
Some of my homegrown bookmarlets.
/*
* Bookmarklets are a bit of a lost art these days,
* most people don't even know they exist anymore.
* They are lighter than any "extension", and can
* still perform really complex actions. Writing
* them is also a good way to flex your DOM/JS skills.
*/
// opens current URL on the Way Back Machine. It works on most cases.
javascript:(function(){if(document.URL === "data:text/html,chromewebdata" || document.URL === "chrome-error://chromewebdata/"){location.href='http://web.archive.org/web/*/'+loadTimeData.data_.summary.failedUrl;}else{location.href='http://web.archive.org/web/*/'+document.URL;}}())
// cleans wikipedia article (so I can run it through a Text-to-Speech engine)
javascript:(function(){function remove_these_fuckers(e,type){if(type==='class'){var r=document.getElementsByClassName(e);}if(type==='tag'){var r=document.getElementsByTagName(e);}while(r.length){r[0].parentNode.removeChild(r[0]);}}remove_these_fuckers('table','tag');remove_these_fuckers('img','tag');remove_these_fuckers('toc','class');remove_these_fuckers('thumbcaption','class');remove_these_fuckers('thumb','class');remove_these_fuckers('reference','class')})();
/*
* Omniglot.com has a couple example sentecenes for hundreds of languages, but
* they include the audio files like ~links~ instead of using the damn ~audio~ tag.
* I asked the site owner to change it and ever volunteered to do it... he didn't
* answer me back. Then I made a bookmarlet that would transform all <a> links to
* audio files into a <audio> links I could play without opening a new tab.
*/
javascript:(function(){links%3Ddocument.getElementsByTagName%28"a"%29%3Bfor%28var i%3D0%3Bi<links.length%3Bi++%29if%28links%5Bi%5D.href.endsWith%28".mp3"%29%29%7Bconsole.log%28links%5Bi%5D.href%29%3Bvar sound%3Ddocument.createElement%28"audio"%29%3Bsound.controls%3D"controls"%3Bsound.src%3Dlinks%5Bi%5D.href%3Bsound.type%3D"audio/mpeg"%3Bsound.style.width%3D"70px"%3Bsound.style.margin%3D"10px"%3Blinks%5Bi%5D.parentNode.appendChild%28sound%29%7D%3B}());
// opens an alert, you insert the game key, it takes you to the register page.
javascript:void(location.href='https://store.steampowered.com/account/registerkey?key='+prompt("Insert Steam key"))
// deletes any element you click on.
javascript:document.addEventListener('click', function (e){e.srcElement.parentNode.removeChild(e.srcElement);console.log(e);e.stopPropagation();},true);
// keeps scrolling down the page.
javascript:void(setInterval( () => scrollBy({ top: 2, behavior: 'smooth' }), 30))
// set all audio elements to 2.25 playback rate.
javascript:Array.from(document.getElementsByTagName('audio'), x => x.playbackRate = 2.25)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment