Last active
July 8, 2017 20:16
-
-
Save sardisson/ba3646b1d30b847b6ad4a523573093e1 to your computer and use it in GitHub Desktop.
Turns javascript: links (bookmarklets) into links that are bookmarkable in Mobile Safari (which can then be edited back into working bookmarklets)
This file contains 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
(function() { | |
var i, elms = document.getElementsByTagName("a"); | |
var bH = window.location.href.split(location.search||location.hash||/[?#]/)[0]; | |
for (i=0; i<elms.length; i++) { | |
if (elms[i].href.lastIndexOf("javascript:", 0) === 0) { | |
elms[i].href = elms[i].href.replace("javascript:", bH+"?bookmarklet#javascript:"); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a simple bookmarklet that will turn any javascript: link into a link that can be clicked, loaded, and bookmarked in Mobile Safari. Because Mobile Safari does not support adding bookmarklets directly (only bookmarking the page that is currently loaded, or syncing bookmarks from a desktop browser), adding a bookmarklet on iOS is a cumbersome, multi-step process—especially if the author of the bookmarklet hasn't made a Mobile Safari-friendly link. The process generally involves bookmarking something else and then editing in the bookmarklet code. With this JavaScript installed as a bookmarklet, the steps involved are "reduced" to:
Your bookmarklet is now ready for use.
iOS-friendly bookmarkable version of iOSify Bookmarklets (tap the link, then start at step 3 above to add this to Mobile Safari): iOSify Bookmarklets