BetterFark

I miss FarkAnalReverteresque and smiths

当前为 2016-04-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name BetterFark
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description I miss FarkAnalReverteresque and smiths
  6. // @author LesserEvil
  7. // @match http://*.fark.com
  8. // @match http://*.fark.com/*
  9. // @match http://fark.com/*
  10. // @match https://*.fark.com/*
  11. // @match https://*.fark.com
  12. // @match https://fark.com/*
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. 'use strict';
  17.  
  18. function scrollIntoView(eleID) {
  19. var e = document.getElementById(eleID);
  20. if (!!e && e.scrollIntoView) {
  21. e.scrollIntoView();
  22. }
  23. }
  24.  
  25. function appendElementToBody(elem)
  26. {
  27. document.getElementsByTagName('body')[0].appendChild(elem);
  28. }
  29. function injectStyles(rule) {
  30. var elem = document.createElement("DIV");
  31. elem.innerHTML = '<style>' + rule + '</style>';
  32. appendElementToBody(elem);
  33. }
  34.  
  35. function removeSponsored()
  36. {
  37. var sponsorRows = document.getElementsByClassName("spau");
  38. var i, rowCount=0;
  39. for( i in sponsorRows )
  40. {
  41. if ( typeof(sponsorRows[i]) == "object" )
  42. {
  43. if ( sponsorRows[i].className !== null )
  44. {
  45. rowCount++;
  46. // sponsorRows[i].className = "better_comment";
  47. sponsorRows[i].innerHTML = "<td></td><td></td><td></td><td></td>";
  48. }
  49. }
  50. }
  51. console.log("Removed Sponsored");
  52. }
  53.  
  54. function doRemoveBubbles()
  55. {
  56. var commentIcons = document.getElementsByClassName("icon_comment");
  57. var i, bubbleCount=0;
  58. for( i in commentIcons )
  59. {
  60. if ( typeof(commentIcons[i]) == "object" )
  61. {
  62. if ( commentIcons[i].className !== null )
  63. {
  64. bubbleCount++;
  65. commentIcons[i].className = "better_comment";
  66. }
  67. }
  68. }
  69. console.log("scrubbing "+bubbleCount+" bubbles away");
  70. removeSponsored();
  71.  
  72. }
  73.  
  74. function displayFarkNew()
  75. {
  76. scrollIntoView("new");
  77. }
  78.  
  79. function doBetterFark()
  80. {
  81. console.log("Making Fark a better place for you and me");
  82. var newsContainer = document.querySelectorAll('div#newsContainer')[0];
  83. var mainContainer = document.querySelectorAll('div#container')[0];
  84. if ( newsContainer !== null )
  85. {
  86. newsContainer.style.width = '100%';
  87. }
  88. else
  89. {
  90. console.log("Unable to find div.newsContainer");
  91. }
  92. try
  93. {
  94. if ( mainContainer !== null )
  95. {
  96. if ( mainContainer.style !== null )
  97. {
  98. mainContainer.style.width = '100%';
  99. }
  100. }
  101. else
  102. {
  103. console.log("Unable to find div.container");
  104. }
  105. }
  106. catch(err) {
  107. }
  108. injectStyles('a.icon_comment { border-width: 0px; }');
  109. injectStyles('a.better_comment { font-size: 120%; }');
  110. doRemoveBubbles();
  111. doRemoveBubbles();
  112. doRemoveBubbles();
  113. doRemoveBubbles();
  114. setTimeout(displayFarkNew(),100);
  115. setTimeout(doRemoveBubbles(), 100);
  116. setTimeout(doRemoveBubbles(), 200);
  117. setTimeout(doRemoveBubbles(), 2000);
  118. setTimeout(doRemoveBubbles(), 3000);
  119. setTimeout(doRemoveBubbles(), 4000);
  120. }
  121.  
  122. // <input type="submit" value="NoSpam" class="searchSubmButtonx" onclick="doRemoveBubbles();">
  123. // div = "searchBar"
  124.  
  125. function doStuff()
  126. {
  127. console.log("Cleaning Time");
  128. removeSponsored();
  129. doRemoveBubbles();
  130. }
  131.  
  132.  
  133. setTimeout(doBetterFark(),100);
  134.  
  135. // var searchBar = document.querySelectorAll('div#searchBar')[0];
  136. var searchBar = document.getElementById("searchBar");
  137. if ( searchBar !== null )
  138. {
  139. var btnDoIt = document.createElement("input");
  140. btnDoIt.type="button";
  141. btnDoIt.value="Better Fark";
  142. btnDoIt.onclick = doRemoveBubbles;
  143. searchBar.insertBefore(btnDoIt, searchBar.childNodes[0]);
  144. // searchBar.appendChild(btnDoIt);
  145. }
  146.  
  147.