Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorquinn/1707236 to your computer and use it in GitHub Desktop.
Save victorquinn/1707236 to your computer and use it in GitHub Desktop.
iPad View Source Bookmarklet
javascript:(function(){
/* Bookmarklet for viewing source in iPad Safari */
var pageHTML = document.documentElement.innerHTML;
var otherlib = false;
var jQueryLoaded = false;
document.documentElement.innerHTML = '<!DOCTYPE html><html><head><title>Source of ' + location.href + '</title><meta name="viewport" content="width=device-width" /></head><body><div id="editor" style="height:' + window.innerHeight + 'px;width:' + window.innerWidth + 'px;"></div></body></html>';
/* Load jQuery */
if(typeof jQuery != 'undefined') {
console.log('This page already using jQuery v' + jQuery.fn.jquery);
jQueryLoaded = true;
}
else if (typeof $ == 'function') {
otherlib = true;
console.log('Something else is using $');
}
function getScript(url, success) {
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0],
done = false;
/* Attach handlers for all browsers */
script.onload = script.onreadystatechange = function(){
if ( !done && (!this.readyState
|| this.readyState == 'loaded'
|| this.readyState == 'complete') ) {
done = true;
success();
script.onload = script.onreadystatechange = null;
head.removeChild(script);
}
};
head.appendChild(script);
}
if (!jQueryLoaded) {
getScript('http://code.jquery.com/jquery-latest.min.js', function() {
console.log("jQuery Loaded.");
if (typeof jQuery == 'undefined') {
console.log("Sorry, couldn't load jQuery");
}
else {
console.log("jQuery version " + jQuery.fn.jquery + " loaded.");
if (otherlib) {
console.log("Conflict detected. Use $jq() not $().");
jQuery.noConflict();
}
}
});
}
if (typeof jQuery != 'undefined') {
jQuery(document).ready(function($) {
$('body').attr('style', 'margin:0px;');
/* Load Ace */
$.getScript('https://www.amherst.edu/sites/all/libraries/ace/build/src/ace.js', function() {
console.log("Ace Loaded");
/* Load Theme */
$.getScript('https://www.amherst.edu/sites/all/libraries/ace/build/src/theme-tomorrow_night_eighties.js', function() {
console.log("Theme Loaded");
});
$.getScript('https://www.amherst.edu/sites/all/libraries/ace/build/src/mode-html.js', function() {
console.log("HTML Mode Loaded");
var editor = ace.edit("editor");
var HTMLMode = require("ace/mode/html").Mode;
editor.setShowPrintMargin(false);
editor.insert(pageHTML);
editor.setTheme('ace/theme/tomorrow_night_eighties');
editor.getSession().setMode(new HTMLMode());
editor.getSession().setUseWrapMode(true);
});
});
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment