Hide ReSteems

Button to Toggle ReSTEEMs from a User's steemit.com or golos.io Profile and Feed Pages

当前为 2017-11-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hide ReSteems
  3. // @namespace https://steemit.com/@alexpmorris
  4. // @version 0.16
  5. // @description Button to Toggle ReSTEEMs from a User's steemit.com or golos.io Profile and Feed Pages
  6. // @author @alexpmorris
  7. // @source https://github.com/alexpmorris/HideResteems
  8. // @match https://steemit.com/*
  9. // @match https://golos.io/*
  10. // @grant none
  11. // @require https://code.jquery.com/jquery-1.12.4.min.js
  12. // @require https://greasyfork.org/scripts/6250-waitforkeyelements/code/waitForKeyElements.js?version=23756
  13. // ==/UserScript==
  14.  
  15. // to avoid conflicts if using "Hide Resteems" (HR) with "Steemit Post Vote Slider and Past Payout Monetizer" (SPVS),
  16. // TamperMonkey *must load* HR first (ie. "Settings -> Position" should be lower for HR than for SPVS)!
  17.  
  18. (function() {
  19. 'use strict';
  20.  
  21. var isHiding = false;
  22. var lastPathStr = "";
  23. var lastQueryStr = "";
  24. var showResteemsBtnSrc = "";
  25. var hideResteemsBtnSrc = "";
  26. var validUrl = "";
  27. var totPosts = 0;
  28. var targetTag = "";
  29.  
  30. function triggerRefresh(cnt) {
  31. if ((cnt===null) || (cnt !== totPosts)) {
  32. totPosts = cnt;
  33. lastPathStr="";
  34. }
  35. }
  36. function urlCheckFunction() {
  37. if (lastPathStr !== location.pathname || lastQueryStr !== location.search ||
  38. lastPathStr === null || lastQueryStr === null) {
  39. lastPathStr = location.pathname;
  40. lastQueryStr = location.search;
  41. addReSteemToggleBtn();
  42. }
  43. }
  44. var steemitURLCheckTimer = setInterval (function() { urlCheckFunction(); }, 250);
  45.  
  46. waitForKeyElements ("#posts_list", domCreateHooks);
  47. function domCreateHooks() {
  48. //to capture ajax additions to feeds
  49. var elem = $("#posts_list").parent();
  50. $(elem).unbind('DOMSubtreeModified.hrs');
  51. $(elem).on('DOMSubtreeModified.hrs', "div", function () {
  52. triggerRefresh($("#posts_list ul").length);
  53. });
  54. lastPathStr="";
  55. }
  56.  
  57. function addReSteemToggleBtn() {
  58. validUrl = document.URL;
  59. if (validUrl.startsWith("https://s")) {
  60. validUrl = validUrl.replace("https://steemit.com/","");
  61. targetTag = ".articles__resteem";
  62. } else {
  63. validUrl = validUrl.replace("https://golos.io/","");
  64. targetTag = ".PostSummary__reblogged_by";
  65. }
  66.  
  67. //language support for buttons
  68. var lang = localStorage.getItem("language");
  69. if ((lang === null) || (localStorage.getItem("language") == "en")) {
  70. showResteemsBtnSrc = "https://steemitimages.com/DQmaRcPxCKNV45aPVaWMbBkP7WvJatgkKqtih7ZCfVsLs4r/button_show-resteems.png";
  71. hideResteemsBtnSrc = "https://steemitimages.com/DQmQYXHkLv4A3h8pZ1ntQM1FTTT6knt5EaVUo7hdj2nNAcR/button_hide-resteems.png";
  72. } else {
  73. showResteemsBtnSrc = "https://steemitimages.com/DQmQeP7KVWpKvm3eNepS8HuwHri6BAJaa8XLYvsyXUWP8E6/button_show-resteems_ru.png";
  74. hideResteemsBtnSrc = "https://steemitimages.com/DQmVds1u5g4W1jRnLNtYDEK8Bnt8WaiA3ueg81HMY3fssav/button_hide-resteems_ru.png";
  75. }
  76.  
  77. var userDiv = $("#posts_list");
  78.  
  79. if ((userDiv.length) && (validUrl.startsWith("@")) && ((validUrl.indexOf("/")==-1) || (validUrl.endsWith("/feed"))) ) {
  80.  
  81. if (!$("#rsButton").length) {
  82. var divData = '<button id="rsButton" type="button" style="width:120px; margin-bottom:10px; outline:none;"><img id="rsBtnImg" src="'+hideResteemsBtnSrc+'"></button>';
  83. $(userDiv).prepend(divData);
  84. var elem = $("#rsButton");
  85. $(elem).click(function (e) { toggleResteemsClick(e); });
  86. if (isHiding) { isHiding = false; $(elem).click(); }
  87. } else {
  88. if (isHiding) hidePosts();
  89. }
  90.  
  91. } else {
  92. if (!$("#post_overlay").length) $("#rsButton").remove();
  93. }
  94. }
  95.  
  96. function hidePosts() {
  97. if (validUrl.endsWith("/feed")) $(targetTag).parent('').hide(); else
  98. $(targetTag).filter(function () {return ($(".UserNames",this)[0] == null);}).parent('').hide();
  99. }
  100. function toggleResteemsClick(e) {
  101. if (!isHiding) {
  102. $("#rsBtnImg").attr('src', showResteemsBtnSrc);
  103. hidePosts();
  104. } else {
  105. $("#rsBtnImg").attr('src', hideResteemsBtnSrc);
  106. $(targetTag).parent('').show();
  107. }
  108. isHiding = !isHiding;
  109. }
  110.  
  111. })();