Hide ReSteems

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

当前为 2017-07-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hide ReSteems
  3. // @namespace https://steemit.com/@alexpmorris
  4. // @version 0.14
  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.  
  29. function triggerRefresh(cnt) {
  30. if ((cnt===null) || (cnt !== totPosts)) {
  31. totPosts = cnt;
  32. lastPathStr="";
  33. }
  34. }
  35. function urlCheckFunction() {
  36. if (lastPathStr !== location.pathname || lastQueryStr !== location.search ||
  37. lastPathStr === null || lastQueryStr === null) {
  38. lastPathStr = location.pathname;
  39. lastQueryStr = location.search;
  40. addReSteemToggleBtn();
  41. }
  42. }
  43. var steemitURLCheckTimer = setInterval (function() { urlCheckFunction(); }, 250);
  44.  
  45. waitForKeyElements ("#posts_list", domCreateHooks);
  46. function domCreateHooks() {
  47. //to capture ajax additions to feeds
  48. var elem = $("#posts_list").parent();
  49. $(elem).unbind('DOMSubtreeModified.hrs');
  50. $(elem).on('DOMSubtreeModified.hrs', "div", function () {
  51. triggerRefresh($("#posts_list ul").length);
  52. });
  53. lastPathStr="";
  54. }
  55.  
  56. function addReSteemToggleBtn() {
  57. validUrl = document.URL;
  58. if (validUrl.startsWith("https://s")) validUrl = validUrl.replace("https://steemit.com/",""); else
  59. validUrl = validUrl.replace("https://golos.io/","");
  60.  
  61. //language support for buttons
  62. var lang = localStorage.getItem("language");
  63. if ((lang === null) || (localStorage.getItem("language") == "en")) {
  64. showResteemsBtnSrc = "https://steemitimages.com/DQmaRcPxCKNV45aPVaWMbBkP7WvJatgkKqtih7ZCfVsLs4r/button_show-resteems.png";
  65. hideResteemsBtnSrc = "https://steemitimages.com/DQmQYXHkLv4A3h8pZ1ntQM1FTTT6knt5EaVUo7hdj2nNAcR/button_hide-resteems.png";
  66. } else {
  67. showResteemsBtnSrc = "https://steemitimages.com/DQmQeP7KVWpKvm3eNepS8HuwHri6BAJaa8XLYvsyXUWP8E6/button_show-resteems_ru.png";
  68. hideResteemsBtnSrc = "https://steemitimages.com/DQmVds1u5g4W1jRnLNtYDEK8Bnt8WaiA3ueg81HMY3fssav/button_hide-resteems_ru.png";
  69. }
  70.  
  71. var userDiv = $("#posts_list");
  72.  
  73. if ((userDiv !== null) && (validUrl.startsWith("@")) && ((validUrl.indexOf("/")==-1) || (validUrl.endsWith("/feed"))) ) {
  74.  
  75. if (!$("#rsButton").length) {
  76. var divData = '<button id="rsButton" type="button" style="width:120px; margin-bottom:5px; outline:none;"><img id="rsBtnImg" src="'+hideResteemsBtnSrc+'"></button>';
  77. $(userDiv).prepend(divData);
  78. var elem = $("#rsButton");
  79. $(elem).click(function (e) { toggleResteemsClick(e); });
  80. if (isHiding) { isHiding = false; $(elem).click(); }
  81. } else {
  82. if (isHiding) hidePosts();
  83. }
  84.  
  85. } else if (userDiv === null) $("#rsButton").remove();
  86. }
  87.  
  88. function hidePosts() {
  89. if (validUrl.endsWith("/feed")) $(".PostSummary__reblogged_by").parent('').hide(); else
  90. $(".PostSummary__reblogged_by").filter(function () {return ($(".UserNames",this)[0] == null);}).parent('').hide();
  91. }
  92. function toggleResteemsClick(e) {
  93. if (!isHiding) {
  94. $("#rsBtnImg").attr('src', showResteemsBtnSrc);
  95. hidePosts();
  96. } else {
  97. $("#rsBtnImg").attr('src', hideResteemsBtnSrc);
  98. $(".PostSummary__reblogged_by").parent('').show();
  99. }
  100. isHiding = !isHiding;
  101. }
  102.  
  103. })();