sig easy copy

easy copying on sig

当前为 2015-04-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name sig easy copy
  3. // @author Nick Hall
  4. // @namespace http://soitgo.es
  5. // @include https://soitgo.es/
  6. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
  7. // @version 1.0.1
  8. // @description easy copying on sig
  9. // ==/UserScript==
  10. $(document).ready(function()
  11. {
  12. easycopy.init();
  13. });
  14.  
  15. var easycopy = {
  16. init: function()
  17. {
  18. $('#links .date').append('<span class="easycopy"><a href="#">x</a></span>');
  19. $('.easycopy a').click(easycopy.handleClick);
  20. $('#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;">Click the x to the right of each link to get started.\n</textarea></div><div id="ezc-loading" style="position: fixed; bottom: 0; right: 0;">Loading...</div>');
  21. $('#ezc-loading').hide();
  22. $('#easycopytext').focus(function() {$(this).select();});
  23.  
  24. //Comment this out if you don't want the top link I guess
  25. $('body').append('<div id="toTheTop" style="position: fixed; left: 5px; bottom: 5px;"><a href="#">top</a></div>');
  26. $('#toTheTop').click(function(e)
  27. {
  28. e.preventDefault();
  29. window.scrollTo(0, 0);
  30. });
  31.  
  32. MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
  33. var observer = new MutationObserver(function(mutations)
  34. {
  35. mutations.forEach(function(mutation)
  36. {
  37. if (typeof mutation.addedNodes == "object")
  38. {
  39. $(mutation.addedNodes).find('.date').each(function()
  40. {
  41. $(this).append(' <span class="easycopy"><a href="#">x</a></span>');
  42. $(this).find('a').click(easycopy.handleClick);
  43. });
  44. }
  45. });
  46. });
  47.  
  48. // define what element should be observed by the observer
  49. observer.observe(document, {
  50. subtree: true,
  51. childList: true
  52. });
  53.  
  54. // Set up moving the text area on scroll
  55. var textareaInitialPosition = $('#easycopytext').offset().top - 10;
  56. $(window).scroll(function()
  57. {
  58. if ($(window).scrollTop() > textareaInitialPosition)
  59. {
  60. $('#easycopytext').css('position', 'fixed');
  61. $('#easycopytext').css('top', '10px');
  62. }
  63. else
  64. {
  65. $('#easycopytext').css('position', '');
  66. $('#easycopytext').css('top', '');
  67. }
  68. });
  69. },
  70.  
  71. handleClick: function(event)
  72. {
  73. event.preventDefault();
  74. var url = $(this).parent().parent().prev().find('.title').parent().attr('href'); // This was being really finnicky
  75. $(this).parent().parent().prev().find('.title').css("cssText", "color: #FF0000 !important;");
  76. easycopy.enqueue();
  77. $.get(url, easycopy.populateURLBox);
  78. $(this).remove();
  79. },
  80.  
  81. populateURLBox: function(data)
  82. {
  83. var linkData = "";
  84. $(data).find('#links_mega a').each(function() { linkData += $(this).attr('href') + '\n' });
  85. $('#easycopytext').val($('#easycopytext').val() + linkData);
  86. easycopy.dequeue();
  87. },
  88.  
  89. loadingCount: 0,
  90.  
  91. enqueue: function()
  92. {
  93. easycopy.loadingCount++;
  94. console.log("Current queued: " + easycopy.loadingCount);
  95. $('#easycopytext').prop('disabled', true);
  96. $('#easycopytext').css('user-select', 'none');
  97. $('#ezc-loading').show('fast');
  98. },
  99. dequeue: function()
  100. {
  101. easycopy.loadingCount--;
  102. if (easycopy.loadingCount === 0)
  103. {
  104. $('#easycopytext').prop('disabled', false);
  105. $('#easycopytext').css('user-select', 'all');
  106. $('#ezc-loading').hide('slow');
  107. }
  108. }
  109. }