Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. // ==UserScript==
  2. // @id tg-links@carb
  3. // @name IITC Carb: TG Links
  4. // @category Carb
  5. // @version 0.3.1.20160222.103152
  6. // @namespace https://github.com/jonatkins/ingress-intel-total-conversion
  7. // @updateURL http://iitc.carbncl.com/plugins/carb.tg-links.meta.js
  8. // @downloadURL http://iitc.carbncl.com/plugins/carb.tg-links.user.js
  9. // @description [carb-2016-02-22-103152] Copies a portal link into the clipboard, for pasting into Telegram
  10. // @include https://www.ingress.com/intel*
  11. // @include http://www.ingress.com/intel*
  12. // @match https://www.ingress.com/intel*
  13. // @match http://www.ingress.com/intel*
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. /* CHANGELOG
  18. - v0.1 First version
  19. - v0.2 Made the hypertext change between normal and clicked text
  20. - v0.2.1 Shortened the delay
  21. - v0.3 Added a guid query to PortalMapBot, changed plugin to match
  22. - v0.3.1 Removed the "guid" keyword from PortalMapBot queries
  23. */
  24.  
  25. // PLUGIN START
  26. function wrapper(plugin_info) {
  27. // ensure plugin framework is there, even if iitc is not yet loaded
  28. if(typeof window.plugin !== 'function') window.plugin = function() {};
  29.  
  30. //PLUGIN AUTHORS: writing a plugin outside of the IITC build environment? if so, delete these lines!!
  31. //(leaving them in place might break the 'About IITC' page or break update checks)
  32. plugin_info.buildName = 'carb';
  33. plugin_info.dateTimeVersion = '20160222.103152';
  34. plugin_info.pluginId = 'carb.tglinks';
  35. //END PLUGIN AUTHORS NOTE
  36.  
  37. // PLUGIN START
  38.  
  39. // use own namespace for plugin
  40. window.plugin.tgLinks = function() {};
  41.  
  42. window.plugin.tgLinks.normalText = 'TG Link';
  43. window.plugin.tgLinks.clickedText = 'TG Copied';
  44. window.plugin.tgLinks.delay = 1000;
  45.  
  46. window.plugin.tgLinks.copyLink = function(guid) {
  47. var textArea = document.createElement('textarea');
  48. textArea.value = '@portalmapbot ' + guid;
  49. document.body.appendChild(textArea);
  50. textArea.select();
  51. try {
  52. document.execCommand('copy');
  53. $('#tg-links').html(window.plugin.tgLinks.clickedText);
  54. setTimeout(function() {
  55. $('#tg-links').html(window.plugin.tgLinks.normalText);
  56. }, window.plugin.tgLinks.delay);
  57. } catch (err) {
  58. console.log('TGLinks was unable to copy');
  59. }
  60. document.body.removeChild(textArea);
  61. };
  62.  
  63. window.plugin.tgLinks.onPortalDetailsUpdated = function(data) {
  64. var onClick = 'window.plugin.tgLinks.copyLink(\'' + window.selectedPortal + '\')';
  65. var html = $('<div>').html( $('<a>').attr({id: 'tg-links', onclick: onClick, title: 'Copy a Telegram link to the clipboard'}).text(window.plugin.tgLinks.normalText) ).html();
  66. $('.linkdetails').append('<aside>' + html + '</aside>');
  67. };
  68.  
  69. var setup = function() {
  70. addHook('portalDetailsUpdated', window.plugin.tgLinks.onPortalDetailsUpdated);
  71. };
  72.  
  73. // PLUGIN END
  74. setup.info = plugin_info; //add the script info data to the function as a property
  75. if(!window.bootPlugins) window.bootPlugins = [];
  76. window.bootPlugins.push(setup);
  77. // if IITC has already booted, immediately run the 'setup' function
  78. if(window.iitcLoaded && typeof setup === 'function') setup();
  79. } // wrapper end
  80. // inject code into site context
  81. var script = document.createElement('script');
  82. var info = {};
  83. 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 };
  84. script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));
  85. (document.body || document.head || document.documentElement).appendChild(script);
  86.  
  87. // PLUGIN END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement