sig easy copy

easy copying on sig

当前为 2016-05-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name sig easy copy
  3. // @author Nick Hall
  4. // @namespace http://soitgo.es
  5. // @include https://soitgo.es/
  6. // @include https://soitgo.es/?*
  7. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
  8. // @version 1.2.5
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @grant GM_listValues
  12. // @description easy copying on sig
  13. // ==/UserScript==
  14. $(document).ready(function()
  15. {
  16. if ($('#login').length === 0)
  17. {
  18. easycopy.init();
  19. }
  20. });
  21.  
  22. var easycopy = {
  23. init: function()
  24. {
  25. easycopy.loadSettings();
  26. console.log(easycopy.settings);
  27.  
  28. // Add x and + links
  29. $('#links .date').append('<span class="easycopy"><a href="#" class="ezc-links">x</a> <a href="#" class="ezc-thumbs">+</a></span>');
  30. $('.easycopy a.ezc-links').click(easycopy.handleClick);
  31. $('.easycopy a.ezc-thumbs').click(easycopy.thumbsClick);
  32.  
  33. // Link box, loading box
  34. $('#links').before('<div id="ezc-textcontainer" style="height: 100px; clear: both; margin: 0 20px 20px 20px; padding: 0 !important;"><textarea id="easycopytext" style="width: 922px; height: 98px; padding: 0 !important; margin: 0 !important; z-index: 10;" placeholder="Click the x to the right of each link to get started."></textarea></div><div id="ezc-loading" style="position: fixed; bottom: 0; right: 0;">Loading...</div>');
  35. $('#ezc-loading').hide();
  36. $('#easycopytext').focus(function() {$(this).select();});
  37.  
  38. //Comment this out if you don't want the top link I guess
  39. $('body').append('<div id="toTheTop" style="position: fixed; left: 5px; bottom: 5px;"><a href="#">top</a></div>');
  40. $('#toTheTop').click(function(e)
  41. {
  42. e.preventDefault();
  43. window.scrollTo(0, 0);
  44. });
  45.  
  46. // Settings page
  47. var settingsIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuNWWFMmUAAAJ2SURBVDhPjVVJixNBFC69qD9BVBwVFQ+DN/EPCIoHYYbxrqC3HHKc5BAIgWxGzB6ym5iNNGTS2ZeLiKcR5uBfEBM3RNwHpP2eqeeUPR31g0dXV73vq7dUdYu/weFwHK1Wq497vd6Lbrf7sl6vP3U6nSfl8v/B5/OtyqEIBAJXx+OxQTYajYzJZGIEg8E1uSy8Xu9FObRGMpncHAwG3zOZTLJYLBYQ1cfhcGiohrlP5YflR/B5gMh30+m0W9L/wIFwOLxJEXAkPDYLmten06kRi8U8pLGQAtxu9yo7W5E5batN6J3M4/FcknJCuFyuw9lsNkEEdiQBXdc/IPVsKpW6i3LcKRQKqXa7/U71o3EulyvZ7fYjUm6BYqGYY0d6NpvN52qDGH6//7zW1J6pvqVSqSmXhcAxOAHiFRT4C4ePwr9HGS5Il30A51Rnq/OGuw//b9C4hkxXBJ0zXuAdkX5GcpcC3b1HDSEOcUmj0WhsC0Q2YzEWTCQStyVvKaLR6DqJME9G+ooE52bBeDx+S/KWIhKJrFkIvhZ0nbjALJjP55OStxRI2WvmoVk7VOAzuGI3qLC0C1lH77ylecndBxT/eKvVmilN2Q2FQuuYPycMIYxlhiNyVmr8Bu7vSq1We8LR0bNcLm/JZbBUEYLyTpHi0IZwtW6iURvovl9v6XNzqrjXWZvNduifgpQOESg1MhrTHIuRcZlw9S7vCVpBCqpkFiBhFqeziOjvo34H9wTZpBBbv9//bBbEMftaqVTaKEUO7z+oJL+EGKqAWRAf0+ucEhmljW5uSCp9jBdpqlAFzIZfwDGtoW0j0hlsrmnaDlI7LakWEOIn6cMDH2scnnQAAAAASUVORK5CYII=';
  48. $('body').append('<div id="ezc-settings-div" style="position: fixed; width: 800px; max-height: 500px; top: 50%; left: 50%; margin-left: -400px; margin-top: -250px; background-color: ' + $('body').css('background-color') + '; border: 2px solid ' + $('body').css('color') + '; border-radius: 10px; padding: 10px;">\
  49. <h2>Settings</h2>\
  50. <p><label>Show link box by default <input type="checkbox" id="ezc-settings-linkbox" /></label></p>\
  51. <button id="ezc-settings-save">Save</button>\
  52. <p><a href="#" class="ezc-settings-open">Close</a></p>\
  53. </div>');
  54. $('#ezc-settings-div').hide();
  55. $('#ezc-settings-save').click(easycopy.saveSettings);
  56. $('nav .ten.columns.omega').append('<a href="#" class="ezc-settings-open"><img src="' + settingsIcon + '" style="height: 20px; width: 20px; margin-bottom: 5px;" /></a>');
  57. $('.ezc-settings-open').click(function(e) {e.preventDefault(); $('#ezc-settings-div').toggle('fast');});
  58. if(easycopy.settings['showLinkBox']) $('#ezc-settings-linkbox').prop('checked', true);
  59.  
  60. // Another div for status messages
  61. $('body').append('<div id="ezc-status" style="position: fixed; right: 5px; top: 5px; background-color: #191919 !important; color: white !important; padding: 5px !important;">This should never be seen</div>');
  62. $('#ezc-status').hide();
  63.  
  64. MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
  65. var observer = new MutationObserver(function(mutations)
  66. {
  67. mutations.forEach(function(mutation)
  68. {
  69. if (typeof mutation.addedNodes == "object")
  70. {
  71. $(mutation.addedNodes).find('.date').each(function()
  72. {
  73. $(this).append(' <span class="easycopy"><a href="#" class="ezc-links">x</a> <a href="#" class="ezc-thumbs">+</a></span>');
  74. $(this).find('.ezc-links').click(easycopy.handleClick);
  75. $(this).find('.ezc-thumbs').click(easycopy.thumbsClick);
  76. });
  77. }
  78. });
  79. });
  80.  
  81. // define what element should be observed by the observer
  82. observer.observe(document, {
  83. subtree: true,
  84. childList: true
  85. });
  86.  
  87. // Set up moving the text area on scroll
  88. var textareaInitialPosition = $('#easycopytext').offset().top - 10;
  89. $(window).scroll(function()
  90. {
  91. if ($(window).scrollTop() > textareaInitialPosition)
  92. {
  93. $('#easycopytext').css('position', 'fixed');
  94. $('#easycopytext').css('top', '10px');
  95. }
  96. else
  97. {
  98. $('#easycopytext').css('position', '');
  99. $('#easycopytext').css('top', '');
  100. }
  101. });
  102.  
  103. // Throw in some custom inline CSS for voting links (since we need to use !important)
  104. $('head').append('<style type="text/css">\
  105. .ezc-flood {\
  106. color: orange !important;\
  107. }\
  108. .ezc-voted {\
  109. color: green !important;\
  110. }\
  111. .ezc-alreadyvoted {\
  112. color: red !important;\
  113. }\
  114. .easycopy button {\
  115. margin: 0 !important;\
  116. }\
  117. </style>');
  118.  
  119. // Show/hide the link box if we want
  120. $('#middlebar > a:nth-child(4)').after('<button id="ezc-linkToggle">Link Box</button>');
  121. $('#ezc-linkToggle').click(function(e)
  122. {
  123. $('#ezc-textcontainer').toggle('fast');
  124. });
  125. if (!easycopy.settings['showLinkBox']) $('#ezc-textcontainer').hide();
  126. },
  127.  
  128. handleClick: function(event)
  129. {
  130. event.preventDefault();
  131. var url = $(this).parent().parent().prev().find('.title').parent().attr('href'); // This was being really finnicky
  132. $(this).parent().parent().prev().find('.title').css("cssText", "color: #FF0000 !important;");
  133. easycopy.enqueue();
  134. $.get(url, easycopy.populateURLBox);
  135. $(this).remove();
  136. },
  137.  
  138. thumbsClick: function(event)
  139. {
  140. event.preventDefault();
  141. var linkID = $(this).parent().parent().prev().find('.title').parent().attr('href').split(':');
  142. var currentLink = $(this);
  143. if (currentLink.hasClass('ezc-alreadyvoted') || currentLink.hasClass('ezc-voted'))
  144. {
  145. easycopy.displayMessage("Already voted");
  146. return; // Don't pester the server if we've already voted
  147. }
  148. easycopy.enqueue('vote');
  149. $.ajax('ajax.php?i=link&thank=' + linkID[1]).done(function (msg)
  150. {
  151. currentLink.removeClass('ezc-flood');
  152. currentLink.removeClass('ezc-voted');
  153. currentLink.removeClass('ezc-alreadyvoted');
  154. if (msg == 'flood')
  155. {
  156. currentLink.addClass('ezc-flood');
  157. easycopy.displayMessage("Please wait");
  158. console.log("FLOOD!!!");
  159. }
  160. else if (msg)
  161. {
  162. easycopy.displayMessage("Vote successful");
  163. currentLink.addClass('ezc-voted');
  164. console.log("VOTED");
  165. }
  166. else
  167. {
  168. easycopy.displayMessage("Already voted");
  169. currentLink.addClass('ezc-alreadyvoted');
  170. console.log("Already voted");
  171. }
  172. easycopy.dequeue();
  173. }
  174. );
  175. },
  176.  
  177. populateURLBox: function(data)
  178. {
  179. var linkData = "";
  180. var password = $(data).find('#password').text();
  181. linkData += $(data).find('#title').text() + ' [password: ' + password + ']\n';
  182. $(data).find('#links_mega a').each(function() { linkData += $(this).attr('href') + '\n\n' });
  183. $('#easycopytext').val($('#easycopytext').val() + linkData);
  184. easycopy.dequeue();
  185. },
  186.  
  187. loadingCount: 0,
  188.  
  189. enqueue: function(type)
  190. {
  191. easycopy.loadingCount++;
  192. if (type !== 'vote')
  193. {
  194. $('#easycopytext').prop('disabled', true);
  195. $('#easycopytext').css('user-select', 'none');
  196. }
  197. $('#ezc-loading').show('fast');
  198. },
  199.  
  200. dequeue: function(type)
  201. {
  202. easycopy.loadingCount--;
  203. if (easycopy.loadingCount === 0)
  204. {
  205. if (type !== 'vote')
  206. {
  207. $('#easycopytext').prop('disabled', false);
  208. $('#easycopytext').css('user-select', 'all');
  209. }
  210. $('#ezc-loading').hide('slow');
  211. }
  212. },
  213.  
  214. displayMessage: function(message)
  215. {
  216. $('#ezc-status').text(message);
  217. $('#ezc-status').show('fast').delay(3000).fadeOut();
  218. },
  219.  
  220. settings: [],
  221.  
  222. saveSettings: function()
  223. {
  224. GM_setValue('showLinkBox', $('#ezc-settings-linkbox').is(':checked'));
  225. easycopy.displayMessage("Settings saved");
  226. },
  227.  
  228. loadSettings: function()
  229. {
  230. var settings = GM_listValues();
  231. if (settings.length === 0)
  232. {
  233. easycopy.runFirstTime(); // Run if we haven't saved anything yet
  234. settings = GM_listValues(); // Reload
  235. }
  236. for (var i = 0; i < settings.length; i++)
  237. {
  238. easycopy.settings[settings[i]] = GM_getValue(settings[i]);
  239. };
  240. },
  241.  
  242. runFirstTime: function()
  243. {
  244. console.log('Running initial setup...')
  245. console.log('Defaulting link box display to true');
  246. GM_setValue('showLinkBox', true);
  247. }
  248. }