🏠 返回首頁 

Greasy Fork is available in English.

Tumblr Followr

Mass follow and unfollow blogs on Tumblr

  1. // ==UserScript==
  2. // @name Tumblr Followr
  3. // @namespace http://wolfspirals.tumblr.com/
  4. // @version 0.4
  5. // @description Mass follow and unfollow blogs on Tumblr
  6. // @include *://www.tumblr.com/following
  7. // @grant gm_uwin
  8. // @copyright 2015+, Allyson Moisan
  9. // ==/UserScript==
  10. (function () {
  11. var gm_uwin = ( function() {
  12. var a;
  13. try {
  14. a = unsafeWindow == window ? false : unsafeWindow;
  15. // Chrome: window == unsafeWindow
  16. } catch(e) {
  17. }
  18. return a || ( function() {
  19. var el = document.createElement('p');
  20. el.setAttribute('onclick', 'return window;');
  21. return el.onclick();
  22. }());
  23. }());
  24. var $ = gm_uwin.jQuery,
  25. procF_start = 0,
  26. procU_start = 0,
  27. procF_done = 0,
  28. procU_done = 0;
  29. if ( typeof $ !== "undefined") {
  30. $(document).ready(function() {
  31. var s = '<style type="text/css"> #followr, #followr_hide { width: 230px; height: 130px; position: relative; } ' +
  32. '#followr { top: 10px; left: 0px; } #followr_hide { top: -120px; left: 0px; } #followr_hide p { width: 100%; } ' +
  33. '#followr p { width: 100%; margin: 5px 0px; } #followr label, #followr button { color: black; padding: 4px; font-size: 12px; } ' +
  34. '#followr button { text-align: center; border: 1px solid #888; margin: 5px 5px 5px 0px; } #followr input { width: 100%; } ' +
  35. '#followr { z-index: 1; } #followr_hide { z-index: 0; background: #DDD; visibility: hidden; } ' +
  36. '#followr_process, #followr_done { position: absolute; top: 40px; left: 0; text-align: center; font-size: 12px; color: #444; visibility: hidden; }' +
  37. '#followr_process strong, #followr_done strong { font-size: 20px; font-weight: bold; }</style>',
  38. f = '<div id="followr"><p><label for="follows">Follow Blogs (comma/space separated)</label><br /><input id="followr_follows" name="follows" type="text" /></p>' +
  39. '<p><label for="unfollows">Unfollow Blogs (comma/space separated)</label><br /><input id="followr_unfollows" name="unfollows" type="text" /></p>' +
  40. '<p><button id="followr_submit">Submit</button><button id="followr_clear">Clear</button></p></div>' +
  41. '<div id="followr_hide"><p id="followr_process"><strong>PROCESSING...</strong><br />(please wait)</p>' +
  42. '<p id="followr_done"><strong>DONE!</strong><br />(please refresh this page)</p></div>';
  43. $("head").append(s);
  44. $("#right_column").append(f);
  45. $("#followr_submit").click(submitFollowr);
  46. $("#followr_clear").click(clearFollowr);
  47. });
  48. }
  49. function submitFollowr() {
  50. $("#followr_hide").css("z-index", "10");
  51. $("#followr_hide").css("visibility", "visible");
  52. $("#followr_process").css("visibility", "visible");
  53. var follows = $("#followr_follows").get(0).value.replace(/[\s,]+/g, ' ').trim().split(' '),
  54. unfollows = $("#followr_unfollows").get(0).value.replace(/[\s,]+/g, ' ').trim().split(' '),
  55. formkey = $("#form_key").get(0).value;
  56. if (follows.length > 0) {
  57. $(follows).each(function(i,v) {
  58. var fblog = $.trim(v);
  59. if (fblog.length > 0) {
  60. fblog = (fblog).replace(/–/g, "--");
  61. procF_start++;
  62. var aurl = "https://www.tumblr.com/following",
  63. amethod = "POST",
  64. adata = {};
  65. adata.form_key = formkey;
  66. adata.follow_this = fblog;
  67. adata.submit = "";
  68. $.ajax({url: aurl, type: amethod, data: adata}).complete(function(){ procF_done++; });
  69. }
  70. });
  71. }
  72. if (unfollows.length > 0) {
  73. $(unfollows).each(function(i,v) {
  74. var ublog = $.trim(v);
  75. if (ublog.length > 0) {
  76. ublog = (ublog).replace(/–/g, "--");
  77. procU_start++;
  78. var aurl = "https://www.tumblr.com/svc/unfollow",
  79. amethod = "POST",
  80. adata = {};
  81. adata.form_key = formkey;
  82. adata.data = {};
  83. adata.data.tumblelog = ublog,
  84. adata.data.source = "UNFOLLOW_SOURCE_FOLLOWING_PAGE";
  85. $.ajax({url: aurl, type: amethod, data: adata}).complete(function(){ procU_done++; });
  86. }
  87. });
  88. }
  89. checkFollowrDone();
  90. }
  91. function clearFollowr() {
  92. $("#followr_follows").get(0).value = "";
  93. $("#followr_unfollows").get(0).value = "";
  94. }
  95. function checkFollowrDone() {
  96. if(procF_start === procF_done && procU_start === procU_done){
  97. $("#followr_process").css("visibility", "hidden");
  98. $("#followr_done").css("visibility", "visible");
  99. } else {
  100. setTimeout(checkFollowrDone, 1000);
  101. }
  102. }
  103. })();