Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryantheleach/8ba9ed4570544e4b19401e01ab65fbf2 to your computer and use it in GitHub Desktop.
Save ryantheleach/8ba9ed4570544e4b19401e01ab65fbf2 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @id iitc-plugin-copy-comm-to-faction-comm@yukkke9
// @name IITC plugin: Copy comm to faction comm
// @category Info
// @version 0.1.1.20150608.4955
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL none
// @downloadURL none
// @description [local-2015-06-08-004955] Try to determine player levels from the data available in the current view.
// @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel*
// @match https://www.ingress.com/intel*
// @match http://www.ingress.com/intel*
// @include https://intel.ingress.com/intel*
// @match https://intel.ingress.com/intel*
// @include https://www.ingress.com/mission/*
// @include http://www.ingress.com/mission/*
// @match https://www.ingress.com/mission/*
// @match http://www.ingress.com/mission/*
// @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 AUTHORS: writing a plugin outside of the IITC build environment? if so, delete these lines!!
//(leaving them in place might break the 'About IITC' page or break update checks)
plugin_info.buildName = 'local';
plugin_info.dateTimeVersion = '20150608.4955';
plugin_info.pluginId = 'copy-all-comm-to-faction-comm';
//END PLUGIN AUTHORS NOTE
// PLUGIN START ////////////////////////////////////////////////////////
window.CHAT_DATA_MAX_TIME = 3*60*60*1000; // in milliseconds
window.COPY_COMM_MIN_ZOOM = 9;
// use own namespace for plugin
window.plugin.copyAllCommToFactionComm = function() {};
window.plugin.copyAllCommToFactionComm.publicMessages ={};
window.plugin.copyAllCommToFactionComm.gotDataFirstTime = true;
// we prepend a hash sign (#) in front of the player name in storage in order to prevent accessing a pre-defined property
// (like constructor, __defineGetter__, etc.
window.plugin.copyAllCommToFactionComm.setupCallback = function() {
addHook('publicChatDataAvailable', window.plugin.copyAllCommToFactionComm.handleData);
addHook('factionChatDataAvailable', window.plugin.copyAllCommToFactionComm.handleFactionData);
// window.chat.request();
};
window.plugin.copyAllCommToFactionComm.processNewData = function(data) {
var limit = plugin.copyAllCommToFactionComm.getLimit();
$.each(data.result, function(ind, json) {
// skip old data
if(json[1] < limit) return true;
// find player and portal information
var sender;
$.each(json[2].plext.markup, function(ind, markup) {
switch(markup[0]) {
case 'SENDER':
sender = markup[1].plain;
break;
}
});
// skip unusable events
if (sender) {
window.plugin.copyAllCommToFactionComm.publicMessages[data.result[ind][0]] = data.processed[data.result[ind][0]];
}
});
};
window.plugin.copyAllCommToFactionComm.handleData = function(data) {
//console.log("handlePublicData");
plugin.copyAllCommToFactionComm.refreshChatDataIfFirst();
if(window.map.getZoom() < window.COPY_COMM_MIN_ZOOM) return;
plugin.copyAllCommToFactionComm.processNewData(data);
};
window.plugin.copyAllCommToFactionComm.handleFactionData = function(data, result, processed) {
//console.log("handleFactionData");
plugin.copyAllCommToFactionComm.refreshChatDataIfFirst();
if (window.plugin.copyAllCommToFactionComm.publicMessages.length != 0) {
$.extend(data.processed, window.plugin.copyAllCommToFactionComm.publicMessages);
// debugger;
}
};
window.plugin.copyAllCommToFactionComm.getLimit = function() {
return new Date().getTime() - window.CHAT_DATA_MAX_TIME
};
window.plugin.copyAllCommToFactionComm.refreshChatDataIfFirst = function() {
if (window.plugin.copyAllCommToFactionComm.gotDataFirstTime) {
window.plugin.copyAllCommToFactionComm.gotDataFirstTime = false;
window.chat.request();
}
}
var setup = function() {
window.plugin.copyAllCommToFactionComm.setupCallback();
};
// 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);
@ryantheleach
Copy link
Author

Buggy, only captures newly posted all-comms, even if you scroll back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment