// ==UserScript== // @author DanielOnDiordna // @name IITC plugin: Acquired items Share button // @version 1.0.0.20220908.235100 // @updateURL https://softspot.nl/ingress/plugins/iitc-plugin-AcquireditemsSharebutton.meta.js // @downloadURL https://softspot.nl/ingress/plugins/iitc-plugin-AcquireditemsSharebutton.user.js // @description [danielondiordna-1.0.0.20220908.235100] Add a Share button into the Acquired items dialog, after using a Redeem code. // @category Misc // @id iitc-plugin-AcquireditemsSharebutton@danielondiordna // @namespace https://softspot.nl/ingress/ // @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() {}; // use own namespace for plugin window.plugin.AcquireditemsSharebutton = function() {}; var self = window.plugin.AcquireditemsSharebutton; self.id = 'AcquireditemsSharebutton'; self.title = 'Acquired items Share button'; self.version = '1.0.0.20220908.235100'; self.author = 'DanielOnDiordna'; self.changelog = ` Changelog: version 1.0.0.20220908.122900 version 1.0.0.20220908.235100 - first release `; self.namespace = 'window.plugin.' + self.id + '.'; self.pluginname = 'plugin-' + self.id; self.getRedeemText = function(html) { let container = document.createElement('div'); container.innerHTML = html; let text = (!document.querySelector('.redeemReward') ? container.innerText : (document.querySelector('.redeemReward li') ? [...document.querySelectorAll('.redeemReward li')].map((li)=>{return li.innerText;}).join("\n") : document.querySelector('.redeemReward').innerText)); return text; }; self.share = function(html) { let text = self.getRedeemText(html); console.log(text); if (typeof android !== 'undefined' && android?.shareString) { return android.shareString(text); } else if (navigator?.clipboard?.writeText) { navigator.clipboard.writeText(text).then(() => { alert('Acquired items text copied to clipboard'); }).catch(() => { // alert("I'm sorry, link copy failed (does not work on mobile)"); prompt("You can manually copy and share this text:",text); }); } else { prompt("You can manually copy and share this text:",text); } }; self.modify_handleRedeemResponse = function() { let handleRedeemResponse_string = window.handleRedeemResponse.toString(); handleRedeemResponse_string = handleRedeemResponse_string.replace(/(\s+)(buttons = {};)/,"$1$2$1buttons['Share'] = function() { " + self.namespace + "share(html); };"); eval("window.handleRedeemResponse = " + handleRedeemResponse_string); }; var setup = function() { self.modify_handleRedeemResponse(); console.log('IITC plugin loaded: ' + self.title + ' version ' + self.version); }; setup.priority = 'boot'; // make it run ASAP 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);