Last active
October 13, 2020 20:11
-
-
Save johnd0e/5c798813b498c8fb5144baf9c7b7f59f to your computer and use it in GitHub Desktop.
IITC plugin: Eruda mobile console [https://gist.github.com/johnd0e/5c798813b498c8fb5144baf9c7b7f59f/raw/debug-eruda-console.user.js]
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
// ==UserScript== | |
// @id debug-eruda-console | |
// @name IITC plugin: Eruda mobile console | |
// @description Console for Mobile Browsers: https://eruda.liriliri.io | |
// @category Debug | |
// @version 0.3 | |
// @author jd | |
// @namespace https://gist.github.com/johnd0e | |
// @homepageURL https://gist.github.com/johnd0e/5c798813b498c8fb5144baf9c7b7f59f | |
// @supportURL https://gist.github.com/johnd0e/5c798813b498c8fb5144baf9c7b7f59f#new_comment_field | |
// @downloadURL https://gist.github.com/johnd0e/5c798813b498c8fb5144baf9c7b7f59f/raw/debug-eruda-console.user.js | |
// @match https://intel.ingress.com/* | |
// @grant none | |
// ==/UserScript== | |
function wrapper(plugin_info) { | |
// ensure plugin framework is there, even if iitc is not yet loaded | |
if(typeof window.plugin !== 'function') window.plugin = function() {}; | |
// PLUGIN START //////////////////////////////////////////////////////// | |
let retries = 10; | |
function whenReady (resolve, reject) { | |
if (document.querySelector('#map')) { | |
resolve(); | |
} else if (retries>0) { | |
retries--; | |
setTimeout(whenReady, null, resolve, reject); | |
} else { | |
reject('#map not found'); | |
} | |
} | |
function eruda_load (onload) { | |
const script = document.createElement('script'); | |
script.src = '//cdn.jsdelivr.net/npm/eruda'; | |
document.body.appendChild(script); | |
script.onload = onload; | |
} | |
function onload () { | |
storage['eruda'] = true; | |
eruda.init(); | |
let scale; | |
if (devicePixelRatio>1 && innerHeight<700) { scale = 0.7; } | |
eruda.scale(scale); | |
} | |
var storage = sessionStorage; // or localStorage; | |
if (storage['eruda']) { | |
eruda_load(()=>{ | |
whenReady(onload, (reason)=>{ | |
console.warn('eruda: ' + reason); | |
}) | |
}); | |
} | |
function eruda_toggle () { | |
if (typeof eruda === 'undefined') { | |
eruda_load(onload); | |
} else if (typeof eruda.get() === 'undefined') { | |
onload(); | |
} else { | |
storage.removeItem('eruda'); | |
eruda.destroy(); | |
} | |
} | |
function setup () { | |
$('<a title="Console for Mobile Browsers">Eruda</a>') | |
.appendTo($('#toolbox')) | |
.click(eruda_toggle); | |
} | |
setup.priority = 'boot'; | |
// PLUGIN END ////////////////////////////////////////////////////////// | |
setup.info = plugin_info; //add the script info data to the function as a property | |
if(!window.bootPlugins) window.bootPlugins = []; | |
window.bootPlugins.push(setup); | |
// if IITC has already booted, immediately run the 'setup' function | |
if(window.iitcLoaded && typeof setup === 'function') setup(); | |
} // wrapper end | |
// inject code into site context | |
var script = document.createElement('script'); | |
var info = {}; | |
if (typeof GM_info !== 'undefined' && GM_info && GM_info.script) info.script = { version: GM_info.script.version, name: GM_info.script.name, description: GM_info.script.description }; | |
script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');')); | |
(document.body || document.head || document.documentElement).appendChild(script); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment