Cleaner Weibo

Make weibo cleaner.

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
  1. 'use strict';
  2.  
  3. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4.  
  5. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6.  
  7. // ==UserScript==
  8. // @name Cleaner Weibo
  9. // @name:zh-CN 去皮微博
  10. // @name:zh-TW 去皮微博
  11. // @namespace NB-Kevin
  12. // @version 0.1.2
  13. // @description Make weibo cleaner.
  14. // @description:zh-CN 讓微博更乾淨。
  15. // @description:zh-TW 讓微博更乾淨。
  16. // @author Nb/Kevin
  17. // @match http://weibo.com/*
  18. // @match http://www.weibo.com/*
  19. // @match http://d.weibo.com/*
  20. // @match http://s.weibo.com/*
  21. // @grant none
  22. // ==/UserScript==
  23.  
  24. // Transpiled by Babel from ES6 to ES5.
  25. // Edited with WebStorm.
  26.  
  27. /**
  28. * Convert a node list to array.
  29. * @returns {Array.<HTMLElement>}
  30. */
  31. NodeList.prototype.toArray = function () {
  32. var that = this;
  33. return Array.prototype.slice.call(that);
  34. };
  35.  
  36. /**
  37. * Hide an HTML element.
  38. */
  39. HTMLElement.prototype.hide = function () {
  40. if (this.className.indexOf('_CWHide') == -1) this.className += ' _CWHide';
  41. };
  42.  
  43. /**
  44. * Create an element from HTML string.
  45. * @return {HTMLElement} The element.
  46. */
  47. String.prototype.toHTMLElement = function () {
  48. var templateElement = document.createElement('template');
  49. templateElement.innerHTML = this;
  50. return templateElement.content.firstChild;
  51. };
  52.  
  53. /**
  54. * Log to console.
  55. * @param {string} message Message.
  56. */
  57. var log = function log(message) {}
  58. // uncomment this line to enable logging
  59. // console.log(`CleanerWeibo |> ${message}`)
  60.  
  61.  
  62. /**
  63. * Root.
  64. */
  65. ;var CleanerWeibo = {
  66. Resources: {
  67. Elements: {
  68. get HomeFeed() {
  69. var candidate = document.querySelector('[node-type="homefeed"]');
  70. if (candidate == null || candidate == undefined) candidate = document.querySelector('[node-type="feedconfig"]');
  71. return candidate;
  72. }
  73. },
  74.  
  75. Styles: '<style>\n ._CWRightUserName {\n max-width: 175px !important;\n }\n ._CWFeedSendBox {\n padding-bottom: 0 !important;\n }\n ._CWGeneralNavNameIcon {\n max-width: 200px !important;\n }\n ._CWHide {\n display: none !important;\n }\n ._CWNoBackgroundImage {\n background-image: none !important;\n }\n </style>'.toHTMLElement(),
  76.  
  77. Selectors: {
  78. RightWildcard: '[id^="v6_pl_rightmod_"]',
  79. RightVIP: '#v6_trustPagelet_recom_member',
  80. FeedInputTitle: '.title_area',
  81. RightSetSkin: '#v6_pl_content_setskin',
  82. RightWBLevelIcon: '.W_icon_level',
  83. RightWBLevelText: '.icon_member_dis',
  84. GeneralNewIcon: '.W_new, .W_new_count, .W_new_ani',
  85. GeneralWebIM: '#WB_webim',
  86. GeneralPlayer: '.PCD_mplayer',
  87. GeneralSearchPlaceHolder: '.placeholder',
  88. GeneralFooter: '.WB_footer',
  89. FeedTips: '.W_tips',
  90. GeneralNavIcon: '[nm="game"], [nm="find"]',
  91. FeedSendBox: '.send_weibo',
  92. RightUserName: '.name',
  93. GeneralNavNameIcon: '[nm="name"]',
  94. LeftHotWeibo: '[suda-uatrack$="left_hotweibo"]',
  95. GeneralSinaLogo: '[node-type="logolink"]',
  96. FeedTopAd: '#v6_pl_content_biztips',
  97. SingleRightPanel: '[id^="Pl_Core_RecommendList"]',
  98. SingleStarCover: '.WB_starcover',
  99. UserPageSkinUseCount: '.pf_use_num',
  100. UserPageSkinUseForMeAsWell: '.pf_copy_icon',
  101. UserPageFollowerInterest: '[id^="Pl_Core_Ut1UserList"]',
  102. DiscoverLogo: '.logo_box',
  103. SearchTrend: '#pl_weibo_hotband',
  104. SearchLogo: '.search_logo',
  105. SearchFooter: '.search_footer',
  106. FeedVipCover: '.WB_vipcover',
  107. FeedDetail: '.WB_feed_detail',
  108. FeedBottomAdvertisement: '#v6_pl_ad_bottomtip',
  109. GeneralVipIcon: '[href*="vipicon"]',
  110. GeneralLevelIcon: '[class*="icon_member"]',
  111. GeneralClubIcon: '.icon_club',
  112. DiscoverRightPanelAdvertisement: '[id*="Pl_Core_ThirdHtmlData__"]',
  113. SearchRightPanelRecommendProduct: '#pl_common_ali',
  114.  
  115. /**
  116. * Direct selectors.
  117. * @return {string}
  118. */
  119. get DirectSelectors() {
  120. return [this.RightVIP, this.FeedInputTitle, this.RightSetSkin, this.RightWBLevelIcon, this.RightWBLevelText, this.GeneralNewIcon, this.GeneralWebIM, this.GeneralPlayer, this.GeneralSearchPlaceHolder, this.GeneralFooter, this.FeedTips, this.GeneralNavIcon, this.LeftHotWeibo, this.GeneralSinaLogo, this.FeedTopAd, this.SingleRightPanel, this.SingleStarCover, this.UserPageSkinUseCount, this.UserPageSkinUseForMeAsWell, this.UserPageFollowerInterest, this.DiscoverLogo, this.SearchTrend, this.SearchLogo, this.SearchFooter, this.FeedVipCover, this.FeedBottomAdvertisement, this.GeneralVipIcon, this.GeneralLevelIcon, this.GeneralClubIcon, this.DiscoverRightPanelAdvertisement, this.SearchRightPanelRecommendProduct].join(',');
  121. }
  122. },
  123.  
  124. StylePatcher: [{
  125. get selector() {
  126. return CleanerWeibo.Resources.Selectors.FeedSendBox;
  127. },
  128. patcher: function patcher(element) {
  129. if (element.className.indexOf('_CWFeedSendBox') == -1) element.className += ' _CWFeedSendBox';
  130. }
  131. }, {
  132. get selector() {
  133. return CleanerWeibo.Resources.Selectors.RightUserName;
  134. },
  135. patcher: function patcher(element) {
  136. if (element.className.indexOf('_CWRightUserName') == -1) element.className += ' _CWRightUserName';
  137. }
  138. }, {
  139. get selector() {
  140. return CleanerWeibo.Resources.Selectors.FeedDetail;
  141. },
  142. patcher: function patcher(element) {
  143. if (element.className.indexOf('_CWNoBackgroundImage') == -1) element.className += ' _CWNoBackgroundImage';
  144. }
  145. }, {
  146. get selector() {
  147. return CleanerWeibo.Resources.Selectors.GeneralNavNameIcon;
  148. },
  149. patcher: function patcher(element) {
  150. var actualContainer = element.childNodes.toArray()[1];
  151. if (actualContainer.className.indexOf('_CWGeneralNavNameIcon') == -1) actualContainer.className += ' _CWGeneralNavNameIcon';
  152. }
  153. }],
  154.  
  155. /**
  156. * Elements selected by wildcard selectors.
  157. * @returns {Array.<HTMLElement>}
  158. */
  159. get WildcardElements() {
  160. return document.querySelectorAll(this.Selectors.RightWildcard).toArray().filter(function (e) {
  161. return !e.id.endsWith('myinfo');
  162. });
  163. },
  164.  
  165. /**
  166. * Elements selected by direct selectors.
  167. * @returns {Array.<HTMLElement>}
  168. */
  169. get DirectElements() {
  170. return document.querySelectorAll(this.Selectors.DirectSelectors).toArray();
  171. },
  172.  
  173. /**
  174. * All elements to be hidden.
  175. * @returns {Array.<HTMLElement>}
  176. */
  177. get AllElementsToBeHidden() {
  178. return this.WildcardElements.concat(this.DirectElements);
  179. }
  180. },
  181.  
  182. Actions: {
  183. /**
  184. * Begin processing the page.
  185. */
  186. Process: function Process() {
  187. log('begin processing...');
  188. if (this.IsProcessing) return;
  189. this.IsProcessing = true;
  190. CleanerWeibo.Resources.AllElementsToBeHidden.forEach(function (element) {
  191. log('hiding element ' + element);
  192. element.hide();
  193. });
  194. this.IsProcessing = false;
  195. },
  196.  
  197. IsProcessing: false,
  198.  
  199. /**
  200. * Patch style.
  201. */
  202. PatchStyle: function PatchStyle() {
  203. CleanerWeibo.Resources.StylePatcher.forEach(function (patcher) {
  204. new CleanerWeibo.StylePatcher(patcher.selector, patcher.patcher).patch();
  205. });
  206. },
  207.  
  208. /**
  209. * Feed observer.
  210. */
  211. FeedObserver: new MutationObserver(function (mutations) {
  212. CleanerWeibo.Actions.Process();
  213. }),
  214.  
  215. /**
  216. * General observer.
  217. */
  218. GeneralObserver: new MutationObserver(function (mutations) {
  219. CleanerWeibo.Actions.Process();
  220. CleanerWeibo.Actions.PatchStyle();
  221. }),
  222.  
  223. /**
  224. * The timer ID of the interval callback.
  225. */
  226. TimerID: 0,
  227.  
  228. /**
  229. * Monitor home feed.
  230. */
  231. MonitorHomeFeed: function MonitorHomeFeed() {
  232. if (CleanerWeibo.Resources.Elements.HomeFeed !== undefined) {
  233. // home feed has been loaded
  234. if (CleanerWeibo.Resources.Elements.HomeFeed != undefined && CleanerWeibo.Resources.Elements.HomeFeed != null) CleanerWeibo.Actions.FeedObserver.observe(CleanerWeibo.Resources.Elements.HomeFeed, { childList: true });
  235. clearInterval(CleanerWeibo.Actions.TimerID);
  236. }
  237. }
  238. },
  239.  
  240. StylePatcher: function () {
  241. /**
  242. * Create a style patcher.
  243. * @param selector {string} Selector.
  244. * @param patcher {Function} Patcher.
  245. */
  246.  
  247. function StylePatcher(selector, patcher) {
  248. _classCallCheck(this, StylePatcher);
  249.  
  250. this.selector = selector;
  251. this.patcher = patcher;
  252. }
  253.  
  254. /**
  255. * Patch the style.
  256. */
  257.  
  258.  
  259. _createClass(StylePatcher, [{
  260. key: 'patch',
  261. value: function patch() {
  262. var that = this;
  263. document.querySelectorAll(that.selector).toArray().forEach(function (e) {
  264. return that.patcher(e);
  265. });
  266. }
  267. }]);
  268.  
  269. return StylePatcher;
  270. }()
  271. };
  272.  
  273. // register stylesheet
  274. document.body.appendChild(CleanerWeibo.Resources.Styles);
  275.  
  276. // register interval
  277. CleanerWeibo.Actions.TimerID = setInterval(CleanerWeibo.Actions.MonitorHomeFeed, 1500);
  278.  
  279. // register general observer
  280. CleanerWeibo.Actions.GeneralObserver.observe(document.body, { childList: true, attributes: true });
  281.  
  282. // debug entry point
  283. window.cw = CleanerWeibo;