Greasy Fork 支持简体中文。

Yet Another Weibo Filter

新浪微博根据关键词、作者、话题、来源等过滤微博;修改版面。 新浪微博根據關鍵字、作者、話題、來源等篩選微博;修改版面。 filter Sina Weibo by keywords, original, topic, source, etc.; modify layout

目前為 2014-07-16 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Yet Another Weibo Filter
  3. // @namespace https://github.com/tiansh
  4. // @description 新浪微博根据关键词、作者、话题、来源等过滤微博;修改版面。 新浪微博根據關鍵字、作者、話題、來源等篩選微博;修改版面。 filter Sina Weibo by keywords, original, topic, source, etc.; modify layout
  5. // @include http://weibo.com/*
  6. // @include http://www.weibo.com/*
  7. // @version 0.1.19 alpha
  8. // @author 田生
  9. // @copyright 2013+, 田生
  10. // @license The MIT License (MIT); http://opensource.org/licenses/MIT
  11. // @grant GM_xmlhttpRequest
  12. // @grant GM_setValue
  13. // @grant GM_getValue
  14. // @grant GM_addStyle
  15. // @grant GM_registerMenuCommand
  16. // @grant GM_info
  17. // @grant unsafeWindow
  18. // @run-at document-start
  19. // ==/UserScript==
  20.  
  21. // 图片
  22. var images = {
  23. 'filter': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAFEUExURUxpcZ6eno6OjpmZmf////v7+/j4+Pr6+vr6+uzs7MvLy8rKyuzs7Ly8vLy8vO7u7r29vb29ve7u7unp6by8vOrq6ufn5+/v776+vry8vO3t7ejo6Ojo6Ovr6+/v7729ve7u7ry8vO/v7+vr6+jo6L6+vu7u7ry8vO/v7+rq6ujo6L6+vu3t7e/v77e3t+vr6+jo6Jubm5qampqamp+fn7m5uezs7MXFxe7u7p2dnZubm5+fn5ycnOzs7L6+vsDAwMLCwsHBwevr6/Ly8vr6+sPDw+3t7e/v78TExMHBwcnJycXFxff39+np6e7u7vPz8/f39/j4+O/v7/T09Ovr6/////Dw8PT09P///9zc3Pn5+fv7+////+3t7f///9ra2v///8DAwOPj49PT0////8LCwtHR0b+/v+Pj48bGxsHBwcfHx0ifhqUAAABsdFJOUwA/Skoauru8u8K7u40sLY8yMYeULoqRijIxjIiNkI42jTWQko86nDaeoJ08sLRKuLQ1Nj8yUL2twEc9Nzq6op6lqbbGn6K/wKymsqmExsO6foDKuMV+wchsm3qmF8l6l2ZWC7oWtrpSCLq2ugo9naEAAAClSURBVBjTY2DAANGsbOzsHEDAzs7G6gIUCI9Ny8rm4ubmykxNDnIGCniFxKczMjEzMzEmRvqaAwUsvYMTMkB6kyL8HYxBDCuPsLgUBgaWUD9HI4ixNp6cUTEsgZx2hjCLrF3dA3zc7E0QVptaONma6SG5RVvXQF9HHUlAVUNLU00RSUBeSUVZQRJJQEJORlaKD0lAQFxaVEgESUCQX0yYh5cBKwAASvgW88X18swAAAAASUVORK5CYII=',
  24. };
  25.  
  26. // 多行字符串
  27. var funcStr = function (f) {
  28. var s = f.toString().split(/\r\n|\r|\n/g).slice(1, -1).join('\n');
  29. return s;
  30. };
  31.  
  32. // 快速创建一段文档元素
  33. var cewih = function (tag, inner) {
  34. var d = document.createElement(tag);
  35. d.innerHTML = inner;
  36. return d;
  37. };
  38.  
  39.  
  40. // 文本常量
  41. // 请以简体中文为原文,参考这些资料翻译
  42. // http://zh.wikipedia.org/wiki/Template:CGroup/IT
  43. // http://www.microsoft.com/Language/zh-cn/Search.aspx
  44. var text = {
  45. // 基本按钮
  46. 'okButtonTitle': { 'zh-cn': '确定', 'zh-hk': '確定', 'zh-tw': '確定', 'en': 'Confirm' },
  47. 'cancelButtonTitle': { 'zh-cn': '取消', 'zh-hk': '取消', 'zh-tw': '取消', 'en': 'Cancel' },
  48. 'closeButtonTitle': { 'zh-cn': '关闭', 'zh-hk': '關閉', 'zh-tw': '關閉', 'en': 'Close' },
  49. 'configApplyButton': { 'zh-cn': '应用', 'zh-hk': '套用', 'zh-tw': '套用', 'en': 'Apply' },
  50. 'configSaveButton': { 'zh-cn': '保存', 'zh-hk': '儲存', 'zh-tw': '儲存', 'en': 'Save' },
  51. 'configCancelButton': { 'zh-cn': '取消', 'zh-hk': '取消', 'zh-tw': '取消', 'en': 'Cancel' },
  52. 'configStringsAdd': { 'zh-cn': '添加', 'zh-hk': '新增', 'zh-tw': '新增', 'en': 'Add' },
  53. 'configUsersAdd': { 'zh-cn': '添加', 'zh-hk': '新增', 'zh-tw': '新增', 'en': 'Add' },
  54. 'foldedWeiboText': { 'zh-cn': '"来自 @" attr(yawf-author) " 的一条微博被折叠,请点击查看"', 'zh-hk': '"來自 @" attr(yawf-author) " 的一條微博被折疊,請點擊查看"', 'zh-tw': '"來自 @" attr(yawf-author) " 的一條微博被折疊,請點擊查看"', 'en': '"A Weibo from @" attr(yawf-author) " was folded, click to view."' },
  55. // 设置框
  56. 'filter': { 'zh-cn': '过滤器', 'zh-hk': '篩選器', 'zh-tw': '篩選器', 'en': 'Filter' },
  57. 'configDialogTitle': { 'zh-cn': '过滤器设置', 'zh-hk': '篩選器設定', 'zh-tw': '篩選器設定', 'en': 'Filter Settings' },
  58. 'configRefreshNotice': { 'zh-cn': '部分设置修改需要保存后重新载入页面才能生效', 'zh-hk': '部分設定變更需要儲存後重新載入網頁才能生效', 'zh-tw': '部分設定變更需要儲存後重新載入網頁才能生效', 'en': 'Some settings need refresh webpage after save to apply' },
  59. 'whitelistFilterDesc': { 'zh-cn': '总是显示{{{typed}}}', 'zh-hk': '總是顯示{{{typed}}}', 'zh-tw': '總是顯示{{{typed}}}', 'en': 'Always show {{{typed}}}' },
  60. 'blacklistFilterDesc': { 'zh-cn': '隐藏{{{typed}}}', 'zh-hk': '隱藏{{{typed}}}', 'zh-tw': '隱藏{{{typed}}}', 'en': 'Hide {{{typed}}}' },
  61. 'foldlistFilterDesc': { 'zh-cn': '折叠{{{typed}}}', 'zh-hk': '折疊{{{typed}}}', 'zh-tw': '折疊{{{typed}}}', 'en': 'Fold {{{typed}}}' },
  62. 'blacklistActionDesc': { 'zh-cn': '隐藏', 'zh-hk': '隱藏', 'zh-tw': '隱藏', 'en': 'Hide' },
  63. 'foldlistActionDesc': { 'zh-cn': '折叠', 'zh-hk': '折疊', 'zh-tw': '折疊', 'en': 'Fold' },
  64. // 关键词
  65. 'keywordFilterGroupTitle': { 'zh-cn': '内容', 'zh-hk': '內容', 'zh-tw': '內容', 'en': 'Content' },
  66. 'keywordFilterDesc': { 'zh-cn': '关键词', 'zh-hk': '關鍵字', 'zh-tw': '關鍵字', 'en': 'Keyword' },
  67. 'keywordFilterDetails': { 'zh-cn': '包含以下关键词的微博', 'zh-hk': '包含以下關鍵字的微博', 'zh-tw': '包含以下關鍵字的微博', 'en': 'Weibo with these keywords' },
  68. // 正则表达式
  69. 'regexpFilterGroupTitle': { 'zh-cn': '正则', 'zh-hk': '正則', 'zh-tw': '正規', 'en': 'Regexp' },
  70. 'regexpFilterDesc': { 'zh-cn': '正则式', 'zh-hk': '正則式', 'zh-tw': '正規式', 'en': 'Regexp' },
  71. 'regexpFilterDetails': { 'zh-cn': '匹配以下正则表达式的微博', 'zh-hk': '匹配以下正則表達式的微博', 'zh-tw': '匹配以下正規表示式的微博', 'en': 'Weibo matches these regular expressions' },
  72. 'regexpFilterRemark': { 'zh-cn': '书写时不需要对“/”字符转义', 'zh-hk': '書寫時不需要對“/”字符轉義', 'zh-tw': '書寫時不需要對“/”字符轉義', 'en': 'Do not escape "/" in your regexp.' },
  73. 'regexpBadFormedTitle': { 'zh-cn': '非法的正则表达式', 'zh-hk': '不合法的正則表達式', 'zh-tw': '不合法的正規表示式', 'en': 'Illegal Regexp' },
  74. 'regexpBadFormed': { 'zh-cn': '您输入的/{{regexp}}/不能被正确地解析为正则表达式,请检查您的输入。如需关键词屏蔽请到内容标签页设置。', 'zh-hk': '您输入的/{{regexp}}/不能被正确地解析为正则表达式,请检查您的输入。如需关键词屏蔽请到内容标签页面设置。', 'zh-tw': '您輸入的/{{regexp}}/不能被正確地解析為正規表示式,請檢查您的輸入。如需關鍵詞屏蔽請到內容標籤頁面設置。', 'en': 'Can not parse /{{regexp}}/ as regexp. Please check your input. You may hide Weibo by keywords in Content tab page.' },
  75. // 帐号
  76. 'accountFilterGroupTitle': { 'zh-cn': '帐号', 'zh-hk': '帳號', 'zh-tw': '帳號', 'en': 'Account' },
  77. 'accountFilterDesc': { 'zh-cn': '帐号', 'zh-hk': '帳號', 'zh-tw': '帳號', 'en': 'Account' },
  78. 'accountFilterDetails': { 'zh-cn': '来自以下帐号的微博', 'zh-hk': '來自以下帳號的微博', 'zh-tw': '來自以下帳號的微博', 'en': 'Weibo from these accounts' },
  79. 'accountNotExistErrorTitle': { 'zh-cn': '帐号不存在', 'zh-hk': '帳號不存在', 'zh-tw': '帳號不存在', 'en': 'Account does not exist' },
  80. 'accountNotExistError': { 'zh-cn': '不存在名为{{name}}的账号', 'zh-hk': '不存在名為{{name}}的賬號', 'zh-tw': '不存在名為{{name}}的賬號', 'en': 'Account named {{name}} does not exist' },
  81. // 原创
  82. 'originalFilterGroupTitle': { 'zh-cn': '原创', 'zh-hk': '原創', 'zh-tw': '原創', 'en': 'Original' },
  83. 'originalFilterDesc': { 'zh-cn': '帐号', 'zh-hk': '帳號', 'zh-tw': '帳號', 'en': 'Account' },
  84. 'originalFilterDetails': { 'zh-cn': '转发自以下账号的微博', 'zh-hk': '隱藏轉發自以下帳號的微博', 'zh-tw': '隱藏轉發自以下帳號的微博', 'en': 'Hide Weibo forwarded from these accounts' },
  85. // 提到
  86. 'mentionFilterGroupTitle': { 'zh-cn': '提到', 'zh-hk': '提到', 'zh-tw': '提到', 'en': 'Mention' },
  87. 'mentionFilterDesc': { 'zh-cn': '帐号', 'zh-hk': '帳號', 'zh-tw': '帳號', 'en': 'Account' },
  88. 'mentionFilterDetails': { 'zh-cn': '提到以下账号的微博', 'zh-hk': '提到以下帳號的微博', 'zh-tw': '提到以下帳號的微博', 'en': 'Weibo mentioned these accounts' },
  89. // 话题
  90. 'topicFilterGroupTitle': { 'zh-cn': '话题', 'zh-hk': '話題', 'zh-tw': '話題', 'en': 'Topic' },
  91. 'topicFilterDesc': { 'zh-cn': '话题', 'zh-hk': '話題', 'zh-tw': '話題', 'en': 'Topic' },
  92. 'topicFilterDetails': { 'zh-cn': '包含以下话题的微博', 'zh-hk': '包含以下話題的微博', 'zh-tw': '包含以下話題的微博', 'en': 'Weibo with these topics' },
  93. // 来源
  94. 'sourceFilterGroupTitle': { 'zh-cn': '来源', 'zh-hk': '來源', 'zh-tw': '來源', 'en': 'Source' },
  95. 'sourceFilterDesc': { 'zh-cn': '来自', 'zh-hk': '來自', 'zh-tw': '來自', 'en': 'Via' },
  96. 'sourceFilterDetails': { 'zh-cn': '以下来源的微博', 'zh-hk': '以下來源的微博', 'zh-tw': '以下來源的微博', 'en': 'Weibo from these sources' },
  97. 'sourceFilterWarningTitle': { 'zh-cn': '默认来源', 'zh-hk': '預設來源', 'zh-tw': '預設來源', 'en': 'Default Source' },
  98. 'sourceFilterWarning': { 'zh-cn': '不能添加默认来源', 'zh-hk': '不能新增預設來源', 'zh-tw': '不能新增預設來源', 'en': 'You cannot add default source' },
  99. // 超链接
  100. 'hyperlinkFilterGroupTitle': { 'zh-cn': '链接', 'zh-hk': '連結', 'zh-tw': '連結', 'en': 'Link' },
  101. 'hyperlinkFilterDesc': { 'zh-cn': '超链接', 'zh-hk': '超連結', 'zh-tw': '超連結', 'en': 'Hyperlink' },
  102. 'hyperlinkFilterDetails': { 'zh-cn': '包含指向以下网站的超链接的微博', 'zh-hk': '包含指向以下站點的超連結的微博', 'zh-tw': '包含指向以下站點的超連結的微博', 'en': 'Weibo with hyperlink to these website' },
  103. // 更多
  104. 'otherFilterGroupTitle': { 'zh-cn': '更多', 'zh-hk': '其他', 'zh-tw': '其他', 'en': 'More' },
  105. 'adfeedFilterDesc': { 'zh-cn': '隐藏推广微博', 'zh-hk': '隱藏推廣微博', 'zh-tw': '隱藏推廣微博', 'en': 'Hide ad Weibo' },
  106. 'recommandFeedDesc': { 'zh-cn': '隐藏推荐微博', 'zh-hk': '隱藏建議微博', 'zh-tw': '隱藏建議微博', 'en': 'Hide recommand Weibo' },
  107. 'fakeWeiboFilterDesc': { 'zh-cn': '隐藏混入微博列表的其它内容', 'zh-hk': '隱藏混入微博列表的其它內容', 'zh-tw': '隱藏混入微博列表的其它內容', 'en': 'Hide other contents in Weibo list' },
  108. 'deletedForwardFilterDesc': { 'zh-cn': '隐藏已删除微博的转发', 'zh-hk': '隱藏已刪除微博的轉發', 'zh-tw': '隱藏已刪除微博的轉發', 'en': 'Hide forward of deleted Weibo' },
  109. 'voteWeiboFilterDesc': { 'zh-cn': '隐藏投票微博', 'zh-hk': '隱藏投票微博', 'zh-tw': '隱藏投票微博', 'en': 'Hide vote weibo' },
  110. 'blockHiddenWeiboDesc': { 'zh-cn': '告知服务器被隐藏的微博以避免再次加载', 'zh-hk': '告知伺服器被隱藏的微博以避免再次載入', 'zh-tw': '告知伺服器被隱藏的微博以避免再次載入', 'en': 'Send blocked Weibo to server to avoid load it again' },
  111. 'whitelistHighlightDesc': { 'zh-cn': '以该背景色显示白名单的微博:', 'zh-hk': '以該背景色顯示白名單的微博:', 'zh-tw': '以該背景色顯示白名單的微博:', 'en': 'Show Weibo in whitelist with background color: ' },
  112. 'sameAccountFilterDesc': { 'zh-cn': '相同作者的微博:', 'zh-hk': '相同作者的微博:', 'zh-tw': '相同作者的微博:', 'en': 'Weibo from same account: ' },
  113. 'sameForwardFilterDesc': { 'zh-cn': '相同微博的转发:', 'zh-hk': '相同微博的轉發:', 'zh-tw': '相同微博的轉發:', 'en': 'Forward from same Weibo: ' },
  114. 'sameNumberOptionDesc': { 'zh-cn': '超过{{number}}条时', 'zh-hk': '超過{{number}}條時', 'zh-tw': '超過{{number}}條時', 'en': 'display no more than {{number}} ' },
  115. 'sameActionOptionDesc': {'zh-cn': '{{{select}}}', 'zh-hk': '{{{select}}}', 'zh-tw': '{{{select}}}', 'en': 'or {{{select}}} it'},
  116. // 模块
  117. 'layoutFilterGroupTitle': { 'zh-cn': '模块', 'zh-hk': '模組', 'zh-tw': '模組', 'en': 'Module' },
  118. 'layoutFilterGroupDesc': { 'zh-cn': '隐藏以下模块', 'zh-hk': '隱藏以下模組', 'zh-tw': '隱藏以下模組', 'en': 'Hide following modules' },
  119. // 标识图标
  120. 'layoutHideIcon': { 'zh-cn': '标识/图标', 'zh-hk': '標誌/圖示', 'zh-tw': '標誌/圖示', 'en': 'Logo / Icon' },
  121. 'layoutHideIconLevel': { 'zh-cn': '等级', 'zh-hk': 'Level', 'zh-tw': '等級', 'en': 'Level' },
  122. 'layoutHideIconMember': { 'zh-cn': '微博会员', 'zh-hk': '微博會員', 'zh-tw': '微博會員', 'en': 'Weibo VIP / Member' },
  123. 'layoutHideIconApprove': { 'zh-cn': '个人认证', 'zh-hk': '個人認證', 'zh-tw': '個人認證', 'en': 'Personal Authentication / 個人認證' },
  124. 'layoutHideIconApproveCo': { 'zh-cn': '机构认证', 'zh-hk': '企業認證', 'zh-tw': '企業認證', 'en': 'Weibo Verification / 企業認證' },
  125. 'layoutHideIconClub': { 'zh-cn': '微博达人', 'zh-hk': '微博達人', 'zh-tw': '微博達人', 'en': 'Pioneer' },
  126. 'layoutHideIconVGirl': { 'zh-cn': '微博女郎', 'zh-hk': '微博女郎', 'zh-tw': '微博女郎', 'en': 'Weibo girl' },
  127. 'layoutHideIconTaobao': { 'zh-cn': '淘宝商户', 'zh-hk': '淘寶商戶', 'zh-tw': '淘寶商戶', 'en': 'Taobao Merchant' },
  128. // 导航栏
  129. 'layoutHideNav': { 'zh-cn': '导航栏', 'zh-hk': '導覽列', 'zh-tw': '導覽列', 'en': 'Navigation Bar' },
  130. 'layoutHideNavMain': { 'zh-cn': '首页', 'zh-hk': '首頁', 'zh-tw': '首頁', 'en': 'Home' },
  131. 'layoutHideNavHot': { 'zh-cn': '热门', 'zh-hk': '熱門', 'zh-tw': '熱門', 'en': 'Hot' },
  132. 'layoutHideNavApp': { 'zh-cn': '应用', 'zh-hk': '應用', 'zh-tw': '應用', 'en': 'Apps' },
  133. 'layoutHideNavGame': { 'zh-cn': '游戏', 'zh-hk': '遊戲', 'zh-tw': '遊戲', 'en': 'Game' },
  134. 'layoutHideNavMember': { 'zh-cn': '会员菜单', 'zh-hk': '會員功能表', 'zh-tw': '會員功能表', 'en': 'VIP Menu' },
  135. // 左栏
  136. 'layoutHideLeft': { 'zh-cn': '左栏', 'zh-hk': '左欄', 'zh-tw': '左欄', 'en': 'Left Column' },
  137. 'layoutHideLeftToMe': { 'zh-cn': '发给我的', 'zh-hk': '發給我的', 'zh-tw': '發給我的', 'en': 'Send to me' },
  138. 'layoutHideLeftFriends': { 'zh-cn': '好友圈', 'zh-hk': '好友圈', 'zh-tw': '好友圈', 'en': 'Friends' },
  139. 'layoutHideLeftApp': { 'zh-cn': '应用', 'zh-hk': '应用', 'zh-tw': '应用'/* as is */, 'en': 'Apps' },
  140. // 中栏
  141. 'layoutHideMiddle': { 'zh-cn': '中栏', 'zh-hk': '中欄', 'zh-tw': '中欄', 'en': 'Middle Column' },
  142. 'layoutHideMiddleRecommendedTopic': { 'zh-cn': '热门微博(发布框上方)', 'zh-hk': '热门微博(發布框上方)', 'zh-tw': '热门微博(發布框上方)'/* as is */, 'en': '热门微博 (Hot Weibo), top of publisher' },
  143. 'layoutHideMiddleMemberTip': { 'zh-cn': '开通会员提示(底部)', 'zh-hk': '開通會員提示(底部)', 'zh-tw': '開通會員提示(底部)', 'en': 'Tip of Join Weibo VIP, bottom' },
  144. // 右栏
  145. 'layoutHideRight': { 'zh-cn': '右栏', 'zh-hk': '右欄', 'zh-tw': '右欄', 'en': 'Right Column' },
  146. 'layoutHideRightWhole': { 'zh-cn': '整个右栏', 'zh-hk': '整個右欄', 'zh-tw': '整個右欄', 'en': 'Whole Right Column' },
  147. 'layoutHideRightTemplate': { 'zh-cn': '设置模板', 'zh-hk': '背景設定', 'zh-tw': '背景設定', 'en': 'Template Settings' },
  148. 'layoutHideRightInfo': { 'zh-cn': '头像', 'zh-hk': '頭像', 'zh-tw': '頭像', 'en': 'Avatar' },
  149. 'layoutHideRightTrial': { 'zh-cn': '会员资格体验', 'zh-hk': '会员资格体验', 'zh-tw': '会员资格体验'/* as is */, 'en': '会员资格体验 (Trial of VIP)' },
  150. 'layoutHideRightAtten': { 'zh-cn': '关注/粉丝/微博数', 'zh-hk': '關注/粉絲/微博數', 'zh-tw': '關注/粉絲/微博數', 'en': 'Numbers of Following/Followers/Weibo' },
  151. 'layoutHideRightInterest': { 'zh-cn': '可能感兴趣的人', 'zh-hk': '可能感興趣的人', 'zh-tw': '可能感興趣的人', 'en': 'You may know' },
  152. 'layoutHideRightHotTopic': { 'zh-cn': '热门话题', 'zh-hk': '熱門話題', 'zh-tw': '熱門話題', 'en': 'Hot Topic' },
  153. 'layoutHideRightMember': { 'zh-cn': '会员专区', 'zh-hk': '會員專區', 'zh-tw': '會員專區', 'en': 'Weibo VIP' },
  154. 'layoutHideRightWeibo': { 'zh-cn': '热门微博', 'zh-hk': '熱門微博', 'zh-tw': '熱門微博', 'en': 'Hot Weibo' },
  155. 'layoutHideRightLocation': { 'zh-cn': '地点推荐', 'zh-hk': '地點推薦', 'zh-tw': '地點推薦', 'en': 'Location' },
  156. 'layoutHideRightMusic': { 'zh-cn': ' 热门歌曲', 'zh-hk': '熱門歌曲', 'zh-tw': '熱門歌曲', 'en': 'Hot Music' },
  157. 'layoutHideRightMovie': { 'zh-cn': '最新电影', 'zh-hk': '最新電影', 'zh-tw': '最新電影', 'en': 'Hot Movie' },
  158. 'layoutHideRightBook': { 'zh-cn': '人气图书', 'zh-hk': '人氣圖書', 'zh-tw': '人氣圖書', 'en': 'Hot Book' },
  159. 'layoutHideRightNotice': { 'zh-cn': '公告栏', 'zh-hk': '公告欄', 'zh-tw': '公告欄', 'en': 'Bulletin Board' },
  160. // 微博内
  161. 'layoutHideWeibo': { 'zh-cn': '微博内', 'zh-hk': '微博內', 'zh-tw': '微博內', 'en': 'In Weibo' },
  162. 'layoutHideWeiboRecomFeed': { 'zh-cn': '精彩微博推荐', 'zh-hk': '精彩微博推薦', 'zh-tw': '精彩微博推薦', 'en': '精彩微博推荐 (Weibo you may interested in)' },
  163. 'layoutHideWeiboTopicCard': { 'zh-cn': '话题卡片', 'zh-hk': '話題卡片', 'zh-tw': '話題卡片', 'en': 'Topic Cards' },
  164. 'layoutHideWeiboLocationCard': { 'zh-cn': '位置卡片', 'zh-hk': '位置卡片', 'zh-tw': '位置卡片', 'en': 'Location Cards' },
  165. 'layoutHideWeiboFeedTip': { 'zh-cn': '评论框提示横幅', 'zh-hk': '評論框提示橫幅', 'zh-tw': '評論框提示橫幅', 'en': 'Tips for Comment' },
  166. // 个人主页
  167. 'layoutHidePerson': { 'zh-cn': '个人主页', 'zh-hk': '個人主頁', 'zh-tw': '個人主頁', 'en': 'Ones home page' },
  168. 'layoutHidePersonCover': { 'zh-cn': '封面图', 'zh-hk': '封面圖', 'zh-tw': '封面圖', 'en': 'Cover Picture' },
  169. 'layoutHidePersonTemplate': { 'zh-cn': '模板设置', 'zh-hk': '模板設置', 'zh-tw': '模板設置', 'en': 'Template Settings' },
  170. 'layoutHidePersonBadgeIcon': { 'zh-cn': '勋章', 'zh-hk': '勳章', 'zh-tw': '勳章', 'en': 'Badges' },
  171. 'layoutHidePersonStats': { 'zh-cn': '关注/粉丝/微博数', 'zh-hk': '關注/粉絲/微博數', 'zh-tw': '關注/粉絲/微博數', 'en': 'Numbers of Following/Followers/Weibo' },
  172. 'layoutHidePersonMyData': { 'zh-cn': '我的微博人气', 'zh-hk': '我的微博人气', 'zh-tw': '我的微博人气', 'en': '我的微博人气 (My Micro World)' },
  173. 'layoutHidePersonSuggestUser': { 'zh-cn': '可能感兴趣的人', 'zh-hk': '可能感兴趣的人', 'zh-tw': '可能感兴趣的人'/* as is */, 'en': 'Suggested' },
  174. 'layoutHidePersonGroup': { 'zh-cn': '推荐的人', 'zh-hk': '推荐的人', 'zh-tw': '推荐的人'/* as is */, 'en': '推荐的人 (Suggested Group)' },
  175. 'layoutHidePersonRelation': { 'zh-cn': '微关系', 'zh-hk': '微关系', 'zh-tw': '微关系'/* as is */, 'en': 'Relationship' },
  176. 'layoutHidePersonAlbum': { 'zh-cn': '图片', 'zh-hk': '相冊', 'zh-tw': '相冊', 'en': 'Album' },
  177. 'layoutHidePersonHotTopic': { 'zh-cn': '话题', 'zh-hk': '話題', 'zh-tw': '話題', 'en': 'Topic' },
  178. 'layoutHidePersonHotWeibo': { 'zh-cn': '热门微博', 'zh-hk': '熱門微博', 'zh-tw': '熱門微博', 'en': 'Hot Weibo' },
  179. // 杂项
  180. 'layoutHideOther': { 'zh-cn': '杂项', 'zh-hk': '雜項', 'zh-tw': '雜項', 'en': 'Others' },
  181. 'layoutHideOtherAds': { 'zh-cn': '广告', 'zh-hk': '廣告', 'zh-tw': '廣告', 'en': 'Advertisement' },
  182. 'layoutHideOtherFeedRecom': { 'zh-cn': '相关微博推荐', 'zh-hk': '相关推荐', 'zh-tw': '相关推荐', 'en': '相关推荐 (Related Weibo Suggestion)' },
  183. 'layoutHideOtherFooter': { 'zh-cn': '页面底部', 'zh-hk': '頁面底部', 'zh-tw': '頁面底部', 'en': 'Footer' },
  184. 'layoutHideOtherWbIm': { 'zh-cn': '微博桌面推荐(右下)', 'zh-hk': '微博桌面推薦(右下)', 'zh-tw': '微博桌面推薦(右下)', 'en': '微博桌面2014 (Desktop Weibo), bottom right' },
  185. 'layoutHideOtherTip': { 'zh-cn': '功能提示框', 'zh-hk': '功能提示框', 'zh-tw': '功能提示框', 'en': 'Function Tips' },
  186. // 工具
  187. 'toolFilterGroupTitle': { 'zh-cn': '工具', 'zh-hk': '工具', 'zh-tw': '工具', 'en': 'Tool' },
  188. 'clearDefTopicDesc': { 'zh-cn': '清除发布框中的默认话题', 'zh-hk': '清除發布框中的預設話題', 'zh-tw': '清除發布框中的預設話題', 'en': 'Remove default topic in Publisher' },
  189. 'userstyleTitle': { 'zh-cn': '自定义CSS', 'zh-hk': '自訂CSS', 'zh-tw': '自訂CSS', 'en': 'Customize CSS' },
  190. 'userstyleEditDesc': { 'zh-cn': '编辑微博自定义CSS', 'zh-hk': '編輯微博自訂CSS', 'zh-tw': '編輯微博自訂CSS', 'en': 'Edit Weibo Customize CSS' },
  191. 'userstyleEditDetails': { 'zh-cn': 'YAWF CSS: ', 'zh-hk': 'YAWF CSS: ', 'zh-tw': 'YAWF CSS: ', 'en': 'YAWF CSS: ' },
  192. 'showAllGroupDesc': { 'zh-cn': '展开左栏分组', 'zh-hk': '展開左欄分組', 'zh-tw': '展開左欄分組', 'en': 'Unfold groups in left column' },
  193. 'showAllMsgNavDesc': { 'zh-cn': '展开左栏消息', 'zh-hk': '展開左欄消息', 'zh-tw': '展開左欄消息', 'en': 'Unfold news in left column' },
  194. 'unwrapTextDesc': { 'zh-cn': '微博作者和正文同行', 'zh-hk': '微博作者和正文同行', 'zh-tw': '微博作者和正文同行', 'en': 'No line break after author' },
  195. 'viewOriginalDesc': { 'zh-cn': '添加“查看原图”链接', 'zh-hk': '添加“查看原圖”連結', 'zh-tw': '添加“查看原圖”連結', 'en': 'add "Original Picture" link' },
  196. 'viewOriginalText': { 'zh-cn': '查看原图', 'zh-hk': '查看原圖', 'zh-tw': '查看原圖', 'en': 'Original Picture' },
  197. // 脚本
  198. 'scriptFilterGroupTitle': { 'zh-cn': '脚本', 'zh-hk': '腳本', 'zh-tw': '腳本', 'en': 'Script' },
  199. // 导入导出
  200. 'configImportAndExport': { 'zh-cn': '设置', 'zh-hk': '設定', 'zh-tw': '設定', 'en': 'Setting' },
  201. 'configImportButton': { 'zh-cn': '导入', 'zh-hk': '匯入', 'zh-tw': '匯入', 'en': 'Import' },
  202. 'configImportWarningTitle': { 'zh-cn': '设置导入', 'zh-hk': '設定匯入', 'zh-tw': '設定匯入', 'en': 'Setting Import' },
  203. 'configImportWarning': { 'zh-cn': '导入的设置会覆盖您当前已有的设置,确实要导入设置吗?', 'zh-hk': '匯入的設定會覆蓋您當前已有的設定,您確定要匯入設定嗎?', 'zh-tw': '匯入的設定會覆蓋您當前已有的設定,您確定要匯入設定嗎?', 'en': 'The imported settings may replace your current settings. Are you sure you want to import this file?' },
  204. 'configImportSuccessTitle': { 'zh-cn': '设置导入完成', 'zh-hk': '設定匯入完成', 'zh-tw': '設定匯入完成', 'en': 'Import settings' },
  205. 'configImportSuccess': { 'zh-cn': '已经成功地导入了设置', 'zh-hk': '已经成功地匯入了設定', 'zh-tw': '已经成功地匯入了設定', 'en': 'Successfully imported settings' },
  206. 'configImportFailTitle': { 'zh-cn': '设置导入失败', 'zh-hk': '設定匯入失败', 'zh-tw': '設定匯入失败', 'en': 'Import settings' },
  207. 'configImportFail': { 'zh-cn': '导入设置文件时出现错误,可能是使用了错误的文件,文件被损坏或文件的版本不支持', 'zh-hk': '匯入設定檔案時出現錯誤,可能是使用了錯誤的檔案,檔案被損壞或設定檔案的版本不支持', 'zh-tw': '匯入設定檔案時出現錯誤,可能是使用了錯誤的檔案,檔案被損壞或設定檔案的版本不支持', 'en': 'Error occurred during importing process. Wrong file may be used, the file may be broken, or the version of setting file is not supported.' },
  208. 'configExportButton': { 'zh-cn': '导出', 'zh-hk': '匯出', 'zh-tw': '匯出', 'en': 'Export' },
  209. 'configResetButton': { 'zh-cn': '重置', 'zh-hk': '重設', 'zh-tw': '重設', 'en': 'Reset' },
  210. 'configResetWarningTitle': { 'zh-cn': '设置重置', 'zh-hk': '設定重設', 'zh-tw': '設定重設', 'en': 'Setting Reset' },
  211. 'configResetWarning': { 'zh-cn': '这将会清空您当前的所有配置,确实要重置设置吗?', 'zh-hk': '這將會清空您當前的所有設定,您確定要重置設定嗎?', 'zh-tw': '這將會清空您當前的所有設定,您確定要重置設定嗎?', 'en': 'You are deleting all your settings. Are you sure you want to reset your settings?' },
  212. // 调试
  213. 'scriptDebugTitle': { 'zh-cn': '调试', 'zh-hk': '偵錯', 'zh-tw': '偵錯', 'en': 'Debug' },
  214. 'scriptDebug': { 'zh-cn': '在控制台打印调试信息', 'zh-hk': '將偵錯訊息列印到主控台', 'zh-tw': '將偵錯訊息列印到主控台', 'en': 'Print debug info to console' },
  215. // 关于
  216. 'scriptAboutTitle': { 'zh-cn': '关于', 'zh-hk': '關於', 'zh-tw': '關於', 'en': 'About' },
  217. 'scriptAbout': {
  218. 'zh-cn': 'YAWF (Yet Another Weibo Filter) 使用 MIT 协议授权。您可以访问脚本的主页 <a href="https://github.com/tiansh/yawf">https://github.com/tiansh/yawf</a> 获取详细信息。<br />本脚本参考并使用了<a href="https://code.google.com/p/weibo-content-filter/">眼不见心不烦</a>脚本的部分代码。',
  219. 'zh-hk': 'YAWF (Yet Another Weibo Filter) 使用 MIT 協議授權。您可以訪問腳本的主頁 <a href="https://github.com/tiansh/yawf">https://github.com/tiansh/yawf</a> 獲取詳細訊息。<br />本腳本參考並使用了<a href="https://code.google.com/p/weibo-content-filter/">眼不见心不烦</a>腳本的部分代碼。',
  220. 'zh-tw': 'YAWF (Yet Another Weibo Filter) 使用 MIT 協議授權。您可以訪問腳本的主頁 <a href="https://github.com/tiansh/yawf">https://github.com/tiansh/yawf</a> 獲取詳細訊息。<br />本腳本參考並使用了<a href="https://code.google.com/p/weibo-content-filter/">眼不见心不烦</a>腳本的部分代碼。',
  221. 'en': 'YAWF (Yet Another Weibo Filter) is under the MIT License. <br />You may visit project host page <a href="https://github.com/tiansh/yawf">https://github.com/tiansh/yawf</a> for more information. <br />Some codes of this script come from <a href="https://code.google.com/p/weibo-content-filter/">眼不见心不烦 (Weibo Content Filter)</a> script.',
  222. },
  223. };
  224.  
  225. // 页面常量
  226. var html = {
  227. 'cover': '<div node-type="outer" style="position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; background: #000; opacity: 0.3; z-index: 10001;"></div>',
  228. 'dialog': '<div style="position: absolute; z-index: 10001;" node-type="outer" class="W_layer yawf-Layer" id="{{id}}"><div class="bg"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td><div node-type="layoutContent" class="content"><div node-type="title" class="title"><span node-type="title_content">{{title}}</span></div><a node-type="close" title="{{closeButtonTitle}}" class="W_close" href="javascript:void(0);"></a><div node-type="inner"></div></div></td></tr></tbody></table></div></div>',
  229. 'alert': '<div style="position: absolute; z-index: 10001;" node-type="outer" class="W_layer yawf-Layer" id="{{id}}"><div class="bg"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td><div node-type="layoutContent" class="content"><div node-type="title" class="title" style=""><span node-type="title_content">{{title}}</span></div><a node-type="close" title="{{closeButtonTitle}}" class="W_close" href="javascript:void(0);"></a><div node-type="inner"><div class="layer_point" node-type="outer"><dl class="point clearfix"><dt><span node-type="icon" class="icon_{{icon}}M"></span></dt><dd node-type="inner"><p node-type="textLarge" class="S_txt1">{{text}}</p><p node-type="textSmall" class="S_txt2"></p></dd></dl><div class="btn"><a node-type="OK" class="W_btn_a" href="javascript:void(0)"><span class="btn_30px W_f14">{{okButtonTitle}}</span></a></div></div></div></div></td></tr></tbody></table></div></div>',
  230. 'confirm': '<div style="position: absolute; z-index: 10001;" node-type="outer" class="W_layer yawf-Layer" id="{{id}}"><div class="bg"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td><div node-type="layoutContent" class="content"><div node-type="title" class="title" style=""><span node-type="title_content">{{title}}</span></div><a node-type="close" title="{{closeButtonTitle}}" class="W_close" href="javascript:void(0);"></a><div node-type="inner"><div class="layer_point" node-type="outer"><dl class="point clearfix"><dt><span node-type="icon" class="icon_{{icon}}M"></span></dt><dd node-type="inner"><p node-type="textLarge" class="S_txt1">{{text}}</p><p node-type="textComplex" class="S_txt2" style="display: none;"></p><p node-type="textSmall" class="S_txt2" style="display: none;"></p></dd></dl><div class="btn"><a node-type="OK" class="W_btn_a" href="javascript:void(0)"><span class="btn_30px W_f14">{{okButtonTitle}}</span></a><a node-type="cancel" class="W_btn_b" href="javascript:void(0)"><span class="btn_30px W_f14">{{cancelButtonTitle}}</span></a></div></div></div></div></td></tr></tbody></table></div></div>',
  231. 'icon': '<div class="gn_setting" node-type="filter"><i><a class="gn_tab gn_filter" href="#"><span class="ico">{{filter}}</span></a></i></div>',
  232. 'configHeaderTop': '<div class="profile_tab S_line5 yawf-config-header" node-type="yawf-config-header"><ul class="pftb_ul S_line1">',
  233. 'configHeaderItem': '<li class="pftb_itm S_line1 {{liclass}}"><a class="pftb_lk S_line5 S_txt1 {{aclass}}" action-type="tab_item" onclick="return false;" href="javascript:void(0);">{{name}}</a>',
  234. 'configHeaderBottom': '</ul></div>',
  235. 'configLayerTop': '<div node-type="yawf-config-body" class="yawf-config-body">',
  236. 'configLayerItem': '<div class="{{name}} yawf-config-layer" node-type="{{name}}" style="display: none;"></div>',
  237. 'configLayerBottom': '</div>',
  238. 'configFooter': '<div class="btn clearfix" node-type="yawf-config-footer"><span class="W_fl S_txt2">{{configRefreshNotice}}</span><a node-type="apply" class="W_btn_b W_btn_b_disable" action-type="apply" href="javascript:;"><span class="btn_30px W_f14">{{configApplyButton}}</span></a><a node-type="save" class="W_btn_a" action-type="save" href="javascript:;"><span class="btn_30px W_f14">{{configSaveButton}}</span></a><a node-type="cancel" class="W_btn_b" action-type="cancel" href="javascript:;"><span class="btn_30px W_f14">{{configCancelButton}}</span></a></div>',
  239. 'configSubtitle': '<div class="yawf-groupSubtitle">{{{text}}}</div>',
  240. 'configText': '<div class="yawf-groupText">{{{text}}}</div>',
  241. 'configBoolean': '<div class="yawf-configBoolean yawf-configItem"><label><input id="yawf-{{key}}" class="W_checkbox yawf-configBooleanInput" type="checkbox" name="yawf-{{key}}"><span class="yawf-configDesc yawf-configBooleanDesc">{{{text}}}</span></label></div>',
  242. 'configString': '<div class="yawf-configString yawf-configItem"><label><span>{{{text}}}</span><textarea id="yawf-{{key}}" class="W_input yawf-configStringInput" name="yawf-{{key}}"></label></div>',
  243. 'configStrings': '<div class="yawf-configStrings yawf-configItem"><form action="#"><label><span class="yawf-configDesc yawf-configStringsDesc">{{{text}}}</span><input id="yawf-{{key}}" class="W_input yawf-configStringsInput" type="text" name="yawf-{{key}}"></label><button id="yawf-add-{{key}}" class="W_btn_a yawf-configAdd" type="submit"><span>{{configStringsAdd}}</span></button></form><ul class="yawf-configStringsItems"></ul></div>',
  244. 'configStringsItem': '<li class="W_btn_arrow tag yawf-configStringsItem"><span>{{[item]}}<a class="W_ico12 icon_close" href="javascript:void(0);"></a></span></li>',
  245. 'configUsers': '<div class="yawf-configUsers yawf-configItem"><form action="#"><label><span class="yawf-configDesc yawf-configUsersDesc">{{{text}}}</span><input id="yawf-{{key}}" class="W_input yawf-configUsersInput" type="text" name="yawf-{{key}}"></label><button id="yawf-add-{{key}}" class="W_btn_a yawf-configAdd" type="submit"><span>{{configUsersAdd}}</span></button></form><ul class="yawf-configUsersItems"></ul></div>',
  246. 'configUsersItem': '<li class="yawf-configUsersItem"><div class="shield_object_card"><div class="card_bg clearfix"><div class="card_pic"><span class="pic"><img class="W_face_radius" width="50" height="50" alt="" src="{{avatar}}"></span></div><div class="card_content"><div class="object_info clearfix"><p class="W_fl"><span class="object_name" uid="{{id}}" title="{{name}}">{{name}}</span></p><p class="W_fr"><a class="W_ico12 icon_close" action-data="uid={{id}}" href="javascript:void(0);"></a></p></div><div class="other_info"></div></div></div></div></li>',
  247. 'configImportExport': '<div class="yawf-configImportExport yawf-configItem"><label><input type="file" style=" width: 1px; height: 1px; margin: 0 -1px 0 0; opacity: 0;" /><span node-type="import" class="W_btn_b" action-type="import"><span class="W_f14">{{configImportButton}}</span></span></label><a node-type="export" class="W_btn_b" action-type="export" href="javascript:;"><span class="W_f14">{{configExportButton}}</span></a><a node-type="reset" class="W_btn_b" action-type="reset" href="javascript:;"><span class="W_f14">{{configResetButton}}</span></a></div>',
  248. 'viewOriginalLink': '<a target="_blank" class="show_big" suda-data="key=tblog_newimage_feed&value=view_original" action-type="maximum" href="javascript:;"><em class="W_ico12 ico_showbig"></em>{{viewOriginalText}}</a><i class="W_vline">|</i>',
  249. 'colorInput': '<input type="color" class="W_f14" style="width: 60px;" />',
  250. 'numberInput': '<input type="number" class="W_f14" style="width: 60px;" />',
  251. 'select': '<select>{{options}}</select>',
  252. 'option': '<option value="{{value}}">{{{text}}}</option>',
  253. };
  254.  
  255. var url = {
  256. 'newcard': 'http://weibo.com/aj/user/newcard?type=1&{{query}}&_t=1&callback={{callback}}',
  257. 'view_ori': 'http://photo.weibo.com/{{uid}}/wbphotos/large/mid/{{mid}}/pid/{{pid}}',
  258. };
  259.  
  260. // 微博过滤规则
  261. var rules = (function () {
  262. var list = [];
  263. var add = function (priority, rule) {
  264. list.push({ 'priority': priority, 'rule': rule });
  265. list.sort(function (x, y) { return y.priority - x.priority; });
  266. };
  267. var parse = function (feed) {
  268. var result = null;
  269. list.some(function (item) {
  270. try { result = item.rule(feed) || result; }
  271. catch (e) { debug('error while parsing rule %o: %o', item.rule, e); }
  272. if (result) debug('%o(%o) -> %s', item.rule, feed, result);
  273. return result;
  274. });
  275. return result;
  276. };
  277. return {
  278. 'add': add,
  279. 'parse': parse,
  280. };
  281. }());
  282.  
  283. // 根据用户界面上的语言做不同调整
  284. var i18n = (function () {
  285. var defaultLang = 'zh-cn';
  286. var lang = null;
  287. var pending = [];
  288. var chose = function (langObj) {
  289. langObj.local = langObj[lang] || langObj[defaultLang];
  290. };
  291. var langs = function (langObj) {
  292. pending.push(langObj);
  293. };
  294. var setLang = function (l) {
  295. lang = l;
  296. pending.map(chose);
  297. pending = [];
  298. i18n = chose;
  299. i18n.lang = l;
  300. };
  301. langs.setLang = setLang;
  302. return langs;
  303. }());
  304.  
  305. // 将字符串用&#dd的形式转义
  306. var escapeXml = function (s) {
  307. return s.replace(/./g, function (c) { return '&#' + c.charCodeAt(0); });
  308. };
  309.  
  310. // 以参数填充字符串
  311. var fillStr = function (base) {
  312. var argdatas = Array.apply(Array, arguments).slice(1);
  313. var datas = argdatas.concat([text]);
  314. return base.replace(/{{([\[{]?([a-zA-Z0-9_-]*)[\]}]?)}}/g, function (o, i, p) {
  315. var ret = null;
  316. datas.some(function (data) {
  317. if (p in data && typeof data[p] === 'string') ret = data[p];
  318. return ret !== null;
  319. });
  320. if (ret) {
  321. if (i[0] === '{') return fillStr.bind(this, ret).apply(null, argdatas);
  322. if (i[0] === '[') return escapeXml(ret);
  323. }
  324. return ret || o;
  325. });
  326. };
  327.  
  328. // 设置项
  329. var config = function (uid) {
  330. var config = {}, keys = [], onputs = [], storageKey = 'user' + uid + 'config';
  331. var tonputs = function (key, value, oldValue) {
  332. onputs.map(function (f) { f(key, value, oldValue); });
  333. };
  334. // 写入到内存
  335. var put = function (key, value) {
  336. if (keys.indexOf(key) === -1) return;
  337. tonputs(key, value, config[key]);
  338. config[key] = value;
  339. return value;
  340. };
  341. // 从内存读取
  342. var get = function (key, value, type) {
  343. if (!(key in config)) return value;
  344. var val = config[key];
  345. if (typeof val === 'undefined') return value;
  346. if (type && (val === null || val.constructor !== type)) return value;
  347. return val;
  348. };
  349. // 读取到内存
  350. var read = function () {
  351. try { config = JSON.parse(GM_getValue(storageKey, '{}')); }
  352. catch (e) { config = {}; }
  353. };
  354. // 从内存写出
  355. var write = function () {
  356. GM_setValue(storageKey, JSON.stringify(config));
  357. };
  358. // 当内存配置被修改时调用
  359. var onput = function (f) {
  360. onputs.push(f);
  361. };
  362. // 从字串导入
  363. var import_ = function (s) {
  364. try {
  365. clear();
  366. s = JSON.parse(s).conf;
  367. Object.keys(s).forEach(function (key) {
  368. put(key, s[key]);
  369. });
  370. return true;
  371. } catch (e) { }
  372. return false;
  373. };
  374. // 导出成为字串
  375. var export_ = function () {
  376. return JSON.stringify({
  377. 'ua': navigator.userAgent,
  378. 'yawf': GM_info.script.name,
  379. 'ver': GM_info.script.version,
  380. 'gm': GM_info.version,
  381. 'conf': config,
  382. }, null, 2);
  383. };
  384. // 清空设置
  385. var clear = function () {
  386. config = {};
  387. tonputs();
  388. };
  389. // 注册键
  390. var reg = function (key) { keys.push(key); };
  391. // 初始化
  392. read();
  393. return {
  394. 'uid': uid,
  395. 'put': put, 'get': get, 'onput': onput,
  396. 'read': read, 'write': write,
  397. 'import': import_, 'export': export_,
  398. 'clear': clear,
  399. 'reg': reg,
  400. };
  401. };
  402.  
  403. var debug = !!GM_getValue('debug', false) ?
  404. console.log.bind(console) : function () { };
  405.  
  406. // 显示右上角过滤器图标
  407. var showIcon = function () {
  408. var p = document.querySelector('.WB_global_nav .gn_person');
  409. if (!p) return setTimeout(showIcon, 100);
  410. var d = cewih('div', html.icon).firstChild;
  411. p.appendChild(d);
  412. var f = document.querySelector('.gn_filter');
  413. f.addEventListener('click', function (e) {
  414. filters.showDialog();
  415. e.preventDefault();
  416. });
  417. };
  418.  
  419. // 对话框
  420. var Form = function (dom, display, details) {
  421. var ok = dom.querySelector('[node-type="OK"]');
  422. var cancel = dom.querySelector('[node-type="cancel"]');
  423. var close = dom.querySelector('[node-type="close"]');
  424. var title = dom.querySelector('.title');
  425. var mouse = null, pos;
  426. var setPos = function (pos) {
  427. var left = pos[0], top = pos[1];
  428. left = Math.min(Math.max(0, left), document.body.clientWidth - dom.clientWidth - 2);
  429. top = Math.min(Math.max(pageYOffset, top), pageYOffset + window.innerHeight - dom.clientHeight - 2);
  430. dom.style.left = left + 'px';
  431. dom.style.top = top + 'px';
  432. return [left, top];
  433. };
  434. var dragMove = function (e) {
  435. var mouse_new = [e.clientX, e.clientY];
  436. pos[0] += mouse_new[0] - mouse[0];
  437. pos[1] += mouse_new[1] - mouse[1];
  438. setPos(pos);
  439. mouse = mouse_new;
  440. };
  441. var dragMoveDone = function () {
  442. document.removeEventListener('mousemove', dragMove);
  443. document.removeEventListener('mouseup', dragMoveDone);
  444. dom.classList.remove('yawf-drag');
  445. if (dom.releaseCapture) { dom.releaseCapture(); }
  446. pos = setPos(pos);
  447. mouse = null;
  448. };
  449. if (title) {
  450. title.style.cursor = 'move';
  451. title.addEventListener('mousedown', function (e) {
  452. mouse = [e.clientX, e.clientY];
  453. document.addEventListener('mousemove', dragMove);
  454. document.addEventListener('mouseup', dragMoveDone);
  455. dom.classList.add('yawf-drag');
  456. if (dom.setCapture) { dom.setCapture(); }
  457. });
  458. }
  459. if (details.onOk) if (ok) ok.addEventListener('click', details.onOk);
  460. if (details.onCancel) {
  461. if (cancel) cancel.addEventListener('click', details.onCancel);
  462. if (close) close.addEventListener('click', details.onCancel);
  463. }
  464. var cover = cewih('div', html.cover).firstChild;
  465. var keys = function (e) {
  466. if (e.keyCode === 13) if (ok) ok.click();
  467. if (e.keyCode === 27) if (close) close.click();
  468. };
  469. var hide = function () {
  470. document.body.removeChild(dom);
  471. document.body.removeChild(cover);
  472. document.removeEventListener('keypress', keys);
  473. };
  474. var show = function (top, left) {
  475. document.body.appendChild(cover);
  476. document.body.appendChild(dom);
  477. if (top == null) top = (window.innerHeight - dom.clientHeight) / 2;
  478. if (left == null) left = (window.innerWidth - dom.clientWidth) / 2;
  479. pos = [left, top + pageYOffset];
  480. setPos(pos);
  481. document.addEventListener('keypress', keys);
  482. document.activeElement.blur();
  483. };
  484. if (display) show();
  485. if (ok) ok.addEventListener('click', hide);
  486. if (cancel) cancel.addEventListener('click', hide);
  487. if (close) close.addEventListener('click', hide);
  488. return {
  489. 'hide': hide,
  490. 'show': show,
  491. };
  492. };
  493.  
  494. // 显示一个对话框
  495. var Dialog = function (id, title, fillFun) {
  496. var dom = cewih('div', fillStr(html.dialog, { 'id': id, 'title': title })).firstChild;
  497. var form = Form(dom, false, {});
  498. fillFun(dom.querySelector('[node-type="inner"]'));
  499. return form;
  500. };
  501.  
  502. // 显示一个提示框
  503. var Alert = function (id, details) {
  504. var dom = cewih('div', fillStr(html.alert, { 'id': id, 'title': details.title, 'text': details.text, 'icon': details.icon || 'warn' })).firstChild;
  505. var form = Form(dom, true, details);
  506. return form;
  507. };
  508.  
  509. var Confirm = function (id, details) {
  510. var dom = cewih('div', fillStr(html.confirm, { 'id': id, 'title': details.title, 'text': details.text, 'icon': details.icon || 'question' })).firstChild;
  511. var form = Form(dom, true, details);
  512. return form;
  513. };
  514.  
  515. // 延迟调用函数
  516. var call = function (f) {
  517. setTimeout.bind(this, f, 0).apply(null, Array.apply(Array, arguments).slice(1));
  518. };
  519.  
  520. // 套上try-catch
  521. var withTry = function (f, fc) {
  522. return function () {
  523. try { f.apply(this, arguments); }
  524. catch (e) {
  525. debug('Exception while run %o: %o (%o)', f, e, e.stack);
  526. if (fc) fc(e);
  527. }
  528. };
  529. };
  530.  
  531. // 管理样式
  532. var css = (function () {
  533. var styleText = '';
  534. var fun = function (css) {
  535. return function () {
  536. if (this.conf) styleText += css + '\n';
  537. };
  538. };
  539. fun.init = function () { GM_addStyle(styleText); };
  540. fun.add = function (css) { styleText += css + '\n'; };
  541. return fun;
  542. }());
  543.  
  544. // 产生一个假的回调函数
  545. var dateStr = (function () {
  546. var last = 0;
  547. return function () {
  548. return '' + (last = Math.max(last + 1, Number(new Date())));
  549. };
  550. }());
  551.  
  552. // 维护账号信息,用于显示
  553. var account = (function () {
  554. var idCache = {}, nameCache = {};
  555. var request = function (queryStr, onsucc, onerror) {
  556. GM_xmlhttpRequest({
  557. 'method': 'GET',
  558. 'url': fillStr(url.newcard, { 'query': queryStr, 'callback': 'STK_' + dateStr() }),
  559. 'onload': withTry(function (resp) {
  560. var respJson = JSON.parse(resp.responseText.replace(/^try{[^{]*\(/, '').replace(/\)}catch\(e\){};$/, ''));
  561. var namecard = cewih('div', respJson.data);
  562. var avatar = namecard.querySelector('.name dt img').getAttribute('src');
  563. var name = namecard.querySelector('.name dd a[uid]').getAttribute('title');
  564. var uid = namecard.querySelector('.name dd a[uid]').getAttribute('uid');
  565. var data = { 'avatar': avatar, 'id': uid, 'name': name };
  566. nameCache[name] = idCache[uid] = data;
  567. onsucc(data);
  568. }, onerror),
  569. 'onerror': function () { onerror(); },
  570. });
  571. return queryStr;
  572. };
  573. var byId = function (id, onsucc, onerror) {
  574. if (idCache[id]) onsucc(idCache[id]);
  575. else request('id=' + id, onsucc, onerror);
  576. };
  577. var byName = function (name, onsucc, onerror) {
  578. if (nameCache[name]) onsucc(nameCache[name]);
  579. else request('name=' + name, onsucc, onerror);
  580. };
  581. return { 'id': byId, 'name': byName };
  582. }());
  583.  
  584. // 过滤器管理器
  585. var filters = (function () {
  586. var list = [], preinit = true;
  587. var add = function (details) {
  588. list.push(details);
  589. if (!preinit) details.init();
  590. return details;
  591. };
  592. var init = function () {
  593. list.forEach(function (x) { x.init(); });
  594. preinit = false;
  595. };
  596. var dialog = null;
  597. var dialogButton = function (dialog, inner) {
  598. var applyButton = inner.querySelector('[action-type="apply"]');
  599. var saveButton = inner.querySelector('[action-type="save"]');
  600. var cancelButton = inner.querySelector('[action-type="cancel"]');
  601. config.onput(function () {
  602. if (applyButton) applyButton.className = 'W_btn_b';
  603. });
  604. applyButton.addEventListener('click', function () {
  605. if (applyButton.classList.contains('W_btn_b_disable')) return;
  606. config.write();
  607. applyButton.className = 'W_btn_b W_btn_b_disable';
  608. });
  609. saveButton.addEventListener('click', function () { config.write(); dialog.hide(); });
  610. cancelButton.addEventListener('click', function () { config.read(); dialog.hide(); });
  611. };
  612. var lastTab = 0;
  613. var dialogTabs = function (list, inner, page) {
  614. var alist = Array.apply(Array, inner.querySelectorAll('.yawf-config-header a'));
  615. var llist = Array.apply(Array, inner.querySelectorAll('.yawf-config-body .yawf-config-layer'));
  616. var choseLList = function (i) {
  617. llist.forEach(function (l) { l.style.display = 'none'; });
  618. alist.forEach(function (a) { a.classList.remove('current'); a.classList.remove('S_bg5'); a.classList.add('S_bg1'); });
  619. llist[i].innerHTML = ''; list[i].show(llist[i]); llist[i].style.display = 'block';
  620. alist[i].classList.add('current'); alist[i].classList.remove('S_bg1'); alist[i].classList.add('S_bg5');
  621. lastTab = i;
  622. };
  623. list.map(function (filter, i) {
  624. var a = alist[i];
  625. a.addEventListener('mousedown', function () { choseLList(i); });
  626. a.addEventListener('keydown', function () { choseLList(i); });
  627. });
  628. choseLList(page);
  629. };
  630. var showDialog = function (page, count) {
  631. var showDialogInner = function (inner) {
  632. inner.innerHTML = [html.configHeaderTop,
  633. list.map(function (filter, index) {
  634. return fillStr(html.configHeaderItem, {
  635. 'name': text[filter.name + 'Title'],
  636. 'aclass': index === 0 ? 'S_bg5 current' : 'S_bg1',
  637. 'liclass': index === list.length - 1 ? 'pftb_itm_lst' : ' ',
  638. });
  639. }).join(''),
  640. html.configHeaderBottom,
  641. html.configLayerTop,
  642. list.map(function (filter, index) {
  643. return fillStr(html.configLayerItem, {
  644. 'name': filter.name + 'Layer',
  645. });
  646. }).join(''),
  647. html.configLayerBottom,
  648. html.configFooter,
  649. ].join('');
  650. call(function () {
  651. dialogButton(dialog, inner);
  652. dialog.show(0);
  653. });
  654. if (list.indexOf(page) === -1) dialogTabs(list, inner, lastTab);
  655. else dialogTabs(list, inner, list.indexOf(page));
  656. };
  657. if (!(dialog = Dialog('yawf-config', fillStr('{{configDialogTitle}}'), showDialogInner))) {
  658. if (!count || count < 100) setTimeout(showDialog, 100, page, (count || 0) + 1);
  659. }
  660. };
  661. return {
  662. 'add': add,
  663. 'init': init,
  664. 'showDialog': showDialog,
  665. };
  666. }());
  667.  
  668. var blockWeibo = (function () {
  669. var buffer = [], busy = false;
  670. var delay = function () { return 3000 + Math.round(20 * Math.random()) * 100; };
  671. var block = function (mid, callback) {
  672. var done = function () { setTimeout(callback, delay()); };
  673. debug('blocking weibo %s', mid);
  674. GM_xmlhttpRequest({
  675. 'method': 'POST',
  676. 'url': 'http://weibo.com/aj/user/block?_wv=5&__rnd=' + dateStr(),
  677. 'headers': {
  678. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  679. 'Cache-Control': 'no-cache',
  680. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  681. 'Cookie': document.cookie,
  682. 'Referer': location.href,
  683. 'X-Requested-With': 'XMLHttpRequest',
  684. },
  685. 'data': 'filter_type=0&mid=' + mid + '&justhide=0&location=home&_t=0',
  686. 'onload': function (resp) { debug('block %s response: %s', mid, resp.responseText); done(); },
  687. 'onerror': function () { debug('block %s network error', mid); done(); },
  688. });
  689. };
  690. var active = function () {
  691. if (!(busy = !!buffer.length)) return;
  692. var mid = buffer.shift();
  693. block(mid, active);
  694. };
  695. return function (mid) {
  696. buffer.push(mid);
  697. if (!busy) active();
  698. return mid;
  699. };
  700. }());
  701.  
  702. // 检查是否有新的节点
  703. var newNode = (function () {
  704. var callbacks = [], actived = false;
  705. var callAll = function (mutation) {
  706. callbacks.forEach(function (c) { c(mutation); });
  707. };
  708. var observe = function () {
  709. callAll();
  710. (new MutationObserver(function (mutations) {
  711. mutations.forEach(function (mutation) { callAll(mutation); });
  712. })).observe(document.body, { 'childList': true, 'subtree': true });
  713. };
  714. var add = function (callback) {
  715. callbacks.push(withTry(callback));
  716. return callback;
  717. };
  718. var remove = function (callback) {
  719. var found = false;
  720. callback = callback.filter(function (x) {
  721. if (x === callback) return found = true; return false;
  722. });
  723. };
  724. var active = function () {
  725. if (actived) return;
  726. actived = true;
  727. observe();
  728. };
  729. return {
  730. 'add': add,
  731. 'remove': remove,
  732. 'active': active,
  733. };
  734. }());
  735.  
  736. // 添加点击后展开折叠消息的事件
  737. var fixFoldWeibo = (function () {
  738. var fixOne = withTry(function (feed) {
  739. var display = feed.getAttribute('yawf-display').replace(/fold$/g, 'unfold');
  740. var showFeed = function () {
  741. feed.setAttribute('yawf-display', display);
  742. feed.removeEventListener('click', showFeed);
  743. };
  744. var author = feed.querySelector('.WB_name[usercard]').getAttribute('title');
  745. feed.setAttribute('yawf-author', author);
  746. feed.addEventListener('click', showFeed);
  747. });
  748. var fix = function (feed) {
  749. var feeds = [feed].concat(Array.apply(Array, feed.querySelectorAll('.WB_feed_type')));
  750. feeds.forEach(function (feed) {
  751. if (feed.getAttribute('yawf-display').lastIndexOf('-fold') === -1) return;
  752. if (feed.getAttribute('yawf-author')) return;
  753. fixOne(feed);
  754. });
  755. };
  756. fix.init = function () {
  757. css.add(fillStr('[node-type="feed_list"] .WB_feed_type[yawf-display$="-fold"]::before { content: {{foldedWeiboText}}; }'));
  758. };
  759. return fix;
  760. }());
  761.  
  762. var swapParentSonWeibo = function (parent, son) {
  763. var x = cewih('div', '');
  764. ['.WB_face', '.WB_info', '.WB_text', '.WB_func'].map(function (q) {
  765. (function (a, b) {
  766. b.parentNode.replaceChild(x, b);
  767. a.parentNode.replaceChild(b, a);
  768. x.parentNode.replaceChild(a, x);
  769. }(parent.querySelector(q), son.querySelector(q)));
  770. });
  771. var mid = parent.getAttribute('mid');
  772. parent.setAttribute('mid', son.getAttribute('mid'));
  773. son.setAttribute('mid', mid);
  774. // 各种细节的修补(原网站做的太乱了……)
  775. var pf = parent.querySelector('.WB_face'), sf = son.querySelector('.WB_face');
  776. var pfa = pf.querySelector('a'), pfi = pf.querySelector('img');
  777. var sfa = sf.querySelector('a'), sfi = sf.querySelector('img');
  778. if (pfa.href.indexOf('?') === -1) pfa.href += '?from=feed&loc=avatar';
  779. if (sfa.href.indexOf('?') !== -1) sfa.href = sfa.href.slice(0, sfa.href.indexOf('?'));
  780. if (!pfa.title) pfa.title = pfi.title;
  781. if (sfa.title) sfa.removeAttribute('title');
  782. sfi.width = sfi.height = '30'; pfi.width = pfi.height = '50';
  783. return son;
  784. };
  785.  
  786. // 如果有一个微博的子微博都隐藏了,那么就隐藏这个微博的子微博框
  787. var fixSonWeiboDisplay = function (feed) {
  788. if (!feed.querySelector('.WB_feed_together')) return fixFoldWeibo(feed);
  789. var sonList = Array.apply(Array, feed.querySelectorAll('.WB_feed_together .WB_sonFeed .WB_feed_type[yawf-display]'));
  790. // 交换两个子微博
  791. var swapSon = function (p, q) {
  792. console.log('swap: %d %d', p, q);
  793. var x = sonList[p], y = sonList[q];
  794. var fakeNode = document.createElement('div');
  795. x.parentNode.insertBefore(fakeNode, x);
  796. y.parentNode.insertBefore(x, y);
  797. fakeNode.parentNode.insertBefore(y, fakeNode);
  798. fakeNode.parentNode.removeChild(fakeNode);
  799. sonList[p] = y; sonList[q] = x;
  800. };
  801. // 把子微博重新排序一下,按照从想看到不想看的顺序排列,排序算法和一趟快排差不多
  802. var p = 0, q;
  803. ['show', 'unset', 'unfold', 'fold', 'hidden'].forEach(function (display) {
  804. q = sonList.length - 1;
  805. while (p < q) {
  806. if (sonList[p].getAttribute('yawf-display').lastIndexOf(display) !== -1) p++;
  807. else if (sonList[q].getAttribute('yawf-display').lastIndexOf(display) === -1) q--;
  808. else swapSon(p, q);
  809. }
  810. });
  811. // 看看还有多少显示出来的子微博,更新一下子微博的计数
  812. var sonCount = feed.querySelectorAll('.WB_feed_together .WB_sonFeed .WB_feed_type:not([yawf-display$="-hidden"])').length;
  813. if (sonCount === 0) feed.querySelector('.WB_feed_together').setAttribute('yawf-display', 'display-hidden');
  814. else feed.querySelector('[node-type="followNum"]').textContent = sonCount;
  815. // 如果下面更多的按钮已经没用了,就藏起来吧
  816. var foldSonCount = feed.querySelectorAll('[node-type="feed_list_wrapForward"] .WB_feed_type:not([yawf-display$="-hidden"])').length;
  817. if (foldSonCount === 0 && feed.querySelector('[node-type="feed_list_wrapForward"]')) {
  818. feed.querySelector('.WB_feed_together').setAttribute('yawf-sonfold', 'display');
  819. }
  820. // 把原始微博和子微博拆开
  821. var another = feed.cloneNode(true);
  822. feed.parentNode.insertBefore(another, feed.nextSibling);
  823. feed.setAttribute('yawf-withson', 'son');
  824. another.setAttribute('yawf-display', 'display-son');
  825. fixFoldWeibo(feed);
  826. fixFoldWeibo(another);
  827. };
  828.  
  829. var weiboFilter = function () {
  830. var feeds = Array.apply(Array,
  831. document.querySelectorAll('[node-type="feed_list"] .WB_feed_type:not([yawf-display])'));
  832. feeds.forEach(function (feed) {
  833. // 同源合并的微博
  834. var sonFeeds = Array.apply(Array, feed.querySelectorAll('[node-type="feed_list"] .WB_feed_type:not([yawf-display])')), son;
  835. var action = null, parentAction = null;
  836. var needSwap = function (action) {
  837. if (!sonFeeds.length) return false;
  838. if (['hidden', 'fold'].indexOf(action) === -1) return false;
  839. return true;
  840. };
  841. var setAction = function (feed, action) {
  842. feed.setAttribute('yawf-display', 'display-' + action);
  843. }
  844. while (true) {
  845. action = rules.parse(feed) || 'unset';
  846. // 如果父微博被屏蔽或折叠,那么就把下面一条没被屏蔽的拉上来换个位置
  847. if (!needSwap(action)) break;
  848. setAction(swapParentSonWeibo(feed, sonFeeds.pop()), action);
  849. }
  850. parentAction = action;
  851. // 最后处理所有下面的子微博
  852. while (sonFeeds.length) (function (son) {
  853. var action = rules.parse(son) || 'unset';
  854. setAction(son, action);
  855. // 如果一列里面有白名单的,那么把白名单的特别换到外面去
  856. if (parentAction !== 'show' && action === 'show') {
  857. setAction(swapParentSonWeibo(feed, son), parentAction);
  858. parentAction = action;
  859. }
  860. }(sonFeeds.shift()));
  861. setAction(feed, parentAction);
  862. fixSonWeiboDisplay(feed);
  863. });
  864. return feeds;
  865. };
  866.  
  867. var addWeiboFilterListener = (function () {
  868. var listeners = [];
  869. // 逐条进行过滤
  870. newNode.add(function () {
  871. var feeds = weiboFilter();
  872. feeds.forEach(function (feed) {
  873. listeners.forEach(function (f) { f(feed); });
  874. });
  875. });
  876. return function (callback) {
  877. listeners.push(withTry(callback));
  878. };
  879. }());
  880.  
  881. var typedConfig = (function () {
  882. var inits = [];
  883. // 字符串
  884. var baseConfig = function (type) {
  885. return function (key) {
  886. return function (item) {
  887. var skey = item.key + (key ? '.' + key : key);
  888. if (!item['getconf' + key]) item['getconf' + key] = function () {
  889. return item['conf' + key] = config.get(skey, item['default' + key] || type(), type);
  890. };
  891. if (!item['putconf' + key]) item['putconf' + key] = function (conf) {
  892. return config.put(skey, item['conf' + key] = conf);
  893. };
  894. inits.push(function () {
  895. config.reg(skey);
  896. item['putconf' + key](item['getconf' + key]());
  897. });
  898. };
  899. };
  900. };
  901. var init = function () {
  902. while (inits.length) inits.shift()();
  903. };
  904. init.string = baseConfig(String);
  905. init.strings = baseConfig(Array);
  906. init.boolean = baseConfig(Boolean);
  907. init.users = baseConfig(Array);
  908. init.number = baseConfig(Number);
  909. return init;
  910. }());
  911.  
  912. // 根据不同类型生成带有事件的文档节点
  913. var typedHtml = (function () {
  914. // 副标题
  915. var subtitle = function (item) {
  916. return cewih('div', fillStr(html.configSubtitle, item)).firstChild;
  917. };
  918.  
  919. // 文本
  920. var text = function (item) {
  921. return cewih('div', fillStr(html.configText, item)).firstChild;
  922. };
  923.  
  924. // 真假值的设置项
  925. var boolean = function (item) {
  926. var dom = cewih('div', fillStr(html.configBoolean, item)).firstChild;
  927. var input = dom.querySelector('input');
  928. input.checked = item.getconf();
  929. input.addEventListener('change', function () {
  930. item.putconf(input.checked);
  931. });
  932. return dom;
  933. };
  934.  
  935. // 字符串的设置项
  936. var string = function (item) {
  937. var dom = cewih('div', fillStr(html.configString, item)).firstChild;
  938. var textarea = dom.querySelector('textarea');
  939. textarea.value = item.getconf();
  940. textarea.addEventListener('change', function () { item.putconf(textarea.value); });
  941. textarea.addEventListener('keypress', function () { item.putconf(textarea.value); });
  942. return dom;
  943. };
  944.  
  945. // 字符串数组设置项模板
  946. var items = function (base, genli, item) {
  947. var dom = cewih('div', fillStr(base, item)).firstChild;
  948. var form = dom.querySelector('form'), input = dom.querySelector('input'), ul = dom.querySelector('ul');
  949. var shown = {};
  950. // 将某个已经有的字符串显示到末尾
  951. var moveToEnd = function (x) {
  952. var p = x.parentNode; p.appendChild(p.removeChild(x));
  953. };
  954. // 显示一个新的字符串
  955. var showStrings = function (userinput, str, onsucc, ondone) {
  956. genli(item, userinput, str, function (str, li) {
  957. if (ondone) ondone();
  958. if (!str || !li) return;
  959. if (shown[str]) return moveToEnd(shown[str]);
  960. var del = li.querySelector('a.icon_close');
  961. del.addEventListener('click', function () {
  962. delete shown[str];
  963. if (item.del) item.del(str);
  964. li.parentNode.removeChild(li);
  965. item.putconf(item.getconf().filter(function (x) { return x !== str; }));
  966. });
  967. ul.appendChild(shown[str] = li);
  968. if (onsucc) onsucc(str);
  969. });
  970. };
  971. item.getconf().forEach(function (str) { showStrings(false, str); });
  972. form.addEventListener('submit', function (e) {
  973. e.preventDefault();
  974. var str = input.value;
  975. input.disabled = true;
  976. showStrings(true, str, function (str) {
  977. item.getconf();
  978. item.conf.push(str);
  979. item.putconf(item.conf);
  980. }, function () {
  981. input.value = '';
  982. input.disabled = false;
  983. });
  984. });
  985. return dom;
  986. };
  987.  
  988. // 字符串设置项
  989. var strings = items.bind(null, html.configStrings, function (item, userinput, str, callback) {
  990. if (userinput && item.add && !(str = item.add(str))) callback();
  991. else callback(str, cewih('ul', fillStr(html.configStringsItem, { 'item': item.display ? item.display(str) : str })).firstChild);
  992. });
  993.  
  994. // 用户列表的设置项
  995. var users = items.bind(null, html.configUsers, function (item, userinput, str, callback) {
  996. var showUserNotExistError = function () {
  997. Alert('yawf-user-not-exist', {
  998. 'title': fillStr('{{accountNotExistErrorTitle}}'),
  999. 'text': fillStr('{{{accountNotExistError}}}', { 'name': escapeXml(str) }),
  1000. 'icon': 'error'
  1001. });
  1002. callback();
  1003. };
  1004. if (userinput) {
  1005. if (!(str = str.trim().replace(/^@/, ''))) return;
  1006. account.name(str, function (info) {
  1007. if (!info) showUserNotExistError();
  1008. else if (item.add && !item.add(info)) callback();
  1009. else callback(info.id, cewih('ul', fillStr(html.configUsersItem, info)).firstChild);
  1010. }, showUserNotExistError);
  1011. } else {
  1012. var emptyInfo = { 'id': str, 'name': ' ', 'avatar': ' ' };
  1013. var li = cewih('ul', fillStr(html.configUsersItem, emptyInfo)).firstChild;
  1014. callback(str, li);
  1015. account.id(str, function (info) {
  1016. var u = li.querySelector('[uid]');
  1017. u.setAttribute('uid', info.id); u.setAttribute('title', info.name); u.textContent = info.name;
  1018. var p = li.querySelector('.pic img');
  1019. p.src = info.avatar;
  1020. });
  1021. }
  1022. });
  1023.  
  1024. return {
  1025. 'subtitle': subtitle,
  1026. 'text': text,
  1027. 'string': string,
  1028. 'strings': strings,
  1029. 'boolean': boolean,
  1030. 'users': users,
  1031. };
  1032. }());
  1033.  
  1034. // 过滤器组
  1035. var filterGroup = function (groupName) {
  1036. var items = [];
  1037. // 向过滤器组里面添加一个项目
  1038. var add = function (item) {
  1039. items.push(item);
  1040. try {
  1041. if (item.type && typedConfig[item.type])
  1042. typedConfig[item.type]('')(item);
  1043. if (item.keys) Object.keys(item.keys).forEach(function (key) {
  1044. if (typedConfig[item.keys[key]]) typedConfig[item.keys[key]](key)(item);
  1045. });
  1046. } catch (e) { }
  1047. return item;
  1048. };
  1049. // 网页被初始化时初始化所有过滤器
  1050. var init = function () {
  1051. items.forEach(withTry(function (item) {
  1052. if (item.keys) { Object.keys(item.keys).forEach(function (key) { }) }
  1053. if (item.init) item.init();
  1054. if (item.rule) rules.add(item.priority || 0, item.rule.bind(item));
  1055. }));
  1056. };
  1057. // 需要显示选项时生成界面
  1058. var show = function (inner) {
  1059. items.forEach(withTry(function (item) {
  1060. var dom = null;
  1061. if (item.show) dom = item.show(dom);
  1062. else if (item.type && typedHtml[item.type])
  1063. dom = typedHtml[item.type](item);
  1064. if (dom && item.shown) item.shown(dom);
  1065. if (dom) inner.appendChild(dom);
  1066. }));
  1067. };
  1068. // 注册到过滤器分组
  1069. var group = {
  1070. 'name': groupName,
  1071. 'show': show,
  1072. 'init': init,
  1073. 'add': add
  1074. };
  1075. return filters.add(group);
  1076. };
  1077.  
  1078. var allInOneFilters = function (details) {
  1079. var filters = [
  1080. { 'type': 'whitelist', 'priority': 1e5, 'action': 'show' },
  1081. { 'type': 'blacklist', 'priority': 0, 'action': 'hidden' },
  1082. { 'type': 'foldlist', 'priority': -1e5, 'action': 'fold' },
  1083. ];
  1084. var typedFilterGroup = filterGroup(details.name + 'FilterGroup');
  1085. filters.forEach(function (filter) {
  1086. typedFilterGroup.add({
  1087. 'type': 'subtitle',
  1088. 'text': '{{{' + filter.type + 'FilterDesc}}}',
  1089. 'typed': '{{' + details.name + 'FilterDetails}}',
  1090. });
  1091. var rule = {
  1092. 'type': details.type || 'strings',
  1093. 'key': 'weibo.filters.' + details.name + '.' + filter.type,
  1094. 'priority': filter.priority,
  1095. 'text': '{{' + details.name + 'FilterDesc}}',
  1096. };
  1097. if (details.add) rule.add = details.add.bind(rule);
  1098. if (details.display) rule.display = details.display.bind(rule);
  1099. rule.rule = details.rule.bind(rule, filter.action);
  1100. typedFilterGroup.add(rule);
  1101. });
  1102. return typedFilterGroup;
  1103. };
  1104.  
  1105. var weiboContentSelector = function (feed, f) {
  1106. var content = feed.querySelector('[node-type="feed_list_content"]');
  1107. var reason = feed.querySelector('[node-type="feed_list_reason"] em');
  1108. var items = [];
  1109. if (content) items = items.concat(Array.apply(Array, f(content)));
  1110. if (reason) items = items.concat(Array.apply(Array, f(reason)));
  1111. return items;
  1112. };
  1113.  
  1114. // 关键字过滤
  1115. var keywordFilterGroup = allInOneFilters({
  1116. 'name': 'keyword',
  1117. 'add': function (s) { return s.trim(); },
  1118. 'rule': function keywordMatch(action, feed) {
  1119. var keywords = this.conf;
  1120. var texts = weiboContentSelector(feed, function (m) {
  1121. return Array.apply(Array, m.childNodes)
  1122. .filter(function (node) { return node.nodeType === Node.TEXT_NODE; })
  1123. .map(function (node) { return node.textContent; });
  1124. }).join(' ').toUpperCase();
  1125. var match = keywords.some(function (keyword) { return texts.indexOf(keyword.toUpperCase()) !== -1; });
  1126. if (match) return action; else return null;
  1127. },
  1128. });
  1129.  
  1130. // 按照正则式过滤
  1131. var regexpFilterGroup = allInOneFilters({
  1132. 'name': 'regexp',
  1133. 'add': function (s) {
  1134. s = s.trim();
  1135. if (s[0] === '/' && s[s.length - 1] === '/') s = s.slice(1, -1);
  1136. try { RegExp(s).exec(''); } catch (e) {
  1137. Alert('yawf-regexp-bad-formed', {
  1138. 'title': fillStr('{{regexpBadFormedTitle}}'),
  1139. 'text': fillStr('{{{regexpBadFormed}}}', { 'regexp': escapeXml(s) }),
  1140. 'icon': 'error'
  1141. });
  1142. s = null;
  1143. }
  1144. return s;
  1145. },
  1146. 'display': function (s) { return '/' + s + '/'; },
  1147. 'rule': function regexpMatch(action, feed) {
  1148. if (!this.regexen) this.regexen = this.conf.map(function (s) {
  1149. try { return RegExp(s); }
  1150. catch (e) { debug('erorr while compile regexp %s : %o', s, e); }
  1151. }).filter(function (x) { return x; });
  1152. var regexen = this.regexen;
  1153. var texts = weiboContentSelector(feed, function (m) {
  1154. return Array.apply(Array, m.childNodes)
  1155. .filter(function (node) { return node.nodeType === Node.TEXT_NODE; })
  1156. .map(function (node) { return node.textContent; });
  1157. }).join(' ');
  1158. var match = regexen.some(function (regexp) {
  1159. return !!(regexp.exec(texts));
  1160. });
  1161. if (match) return action; else return null;
  1162. },
  1163. });
  1164.  
  1165. // 作者用户过滤
  1166. var accountFilterGroup = allInOneFilters({
  1167. 'name': 'account',
  1168. 'type': 'users',
  1169. 'rule': function accountMatch(action, feed) {
  1170. var accounts = this.conf;
  1171. var author = feed.querySelector('.WB_name[usercard]');
  1172. if (!author) return false;
  1173. var id = author.getAttribute('usercard').split('=')[1];
  1174. var match = accounts.some(function (x) { return x === id; });
  1175. if (match) return action; else return null;
  1176. },
  1177. });
  1178.  
  1179. // 原创用户过滤
  1180. var originalFilterGroup = allInOneFilters({
  1181. 'name': 'original',
  1182. 'type': 'users',
  1183. 'rule': function originalMatch(action, feed) {
  1184. var originals = this.conf;
  1185. var originalAuthor = feed.querySelector('.WB_media_expand .WB_info .WB_name');
  1186. if (!originalAuthor) return false;
  1187. var id = originalAuthor.getAttribute('usercard').split('=')[1];
  1188. var match = originals.some(function (x) { return x === id; });
  1189. if (match) return action; else return null;
  1190. },
  1191. });
  1192.  
  1193. // 提到某人的微博
  1194. var mentionFilterGroup = allInOneFilters({
  1195. 'name': 'mention',
  1196. 'type': 'strings',
  1197. 'add': function (s) { return s.trim().replace(/^@/, ''); },
  1198. 'display': function (s) { return '@' + s; },
  1199. 'rule': function mentionMatch(action, feed) {
  1200. var mentions = this.conf;
  1201. var links = weiboContentSelector(feed, function (m) {
  1202. return Array.apply(Array, m.querySelectorAll('a[usercard^="name="][href$="loc=at"]'));
  1203. });
  1204. var match = links.some(function (link) {
  1205. var name = link.getAttribute('usercard').slice('name='.length);
  1206. return mentions.indexOf(name) !== -1;
  1207. });
  1208. if (match) return action; else return null;
  1209. },
  1210. });
  1211.  
  1212. // 话题过滤
  1213. var topicFilterGroup = allInOneFilters({
  1214. 'name': 'topic',
  1215. 'add': function (s) { return s.trim().replace(/#/g, ''); },
  1216. 'display': function (s) { return '#' + s + '#'; },
  1217. 'rule': function (action, feed) {
  1218. var topics = this.conf;
  1219. var list = weiboContentSelector(feed, function (m) {
  1220. return Array.apply(Array, m.querySelectorAll('.a_topic'));
  1221. });
  1222. var text = list.map(function (x) { return x.textContent; }).join('##');
  1223. var match = topics.some(function (topic) { return text.indexOf(topic) !== -1; });
  1224. if (match) return action; else return null;
  1225. },
  1226. });
  1227.  
  1228. // 来源过滤
  1229. var sourceFilterGroup = allInOneFilters({
  1230. 'name': 'source',
  1231. 'add': function (s) {
  1232. s = s.trim();
  1233. if (s === '微博 weibo.com') {
  1234. Alert('yawf-source-filter-warning', {
  1235. 'title': fillStr('{{sourceFilterWarningTitle}}'),
  1236. 'text': fillStr('{{sourceFilterWarning}}'),
  1237. 'icon': 'error'
  1238. });
  1239. s = null;
  1240. }
  1241. return s;
  1242. },
  1243. 'rule': function sourceMatch(action, feed) {
  1244. var sources = this.conf;
  1245. var match = ['[node-type="feed_list_funcLink"] [action-type="app_source"]',
  1246. '.WB_media_expand [action-type="app_source"]'].some(function (qs) {
  1247. var st = feed.querySelector(qs); if (!st) return null;
  1248. var source = st.getAttribute('title') || st.textContent || '未通过审核应用';
  1249. return sources.indexOf(source) !== -1;
  1250. });
  1251. if (match) return action; else return null;
  1252. },
  1253. });
  1254.  
  1255. // 超链接过滤
  1256. var hyperlinkFilterGroup = allInOneFilters({
  1257. 'name': 'hyperlink',
  1258. 'add': function (s) { return s.trim(); },
  1259. 'rule': function hyperlinkMatch(action, feed) {
  1260. var links = this.conf;
  1261. var al = Array.apply(Array, feed.querySelectorAll('a[title]'));
  1262. var match = al.some(function (a) {
  1263. var l = a.getAttribute('title');
  1264. return links.some(function (link) {
  1265. return l.toUpperCase().indexOf(link.toUpperCase()) !== -1;
  1266. });
  1267. });
  1268. if (match) return action; else return null;
  1269. },
  1270. });
  1271.  
  1272.  
  1273. var otherFilterGroup = filterGroup('otherFilterGroup');
  1274.  
  1275. // 推广微博
  1276. otherFilterGroup.add({
  1277. 'type': 'boolean',
  1278. 'key': 'weibo.other.ad_feed',
  1279. 'text': '{{adfeedFilterDesc}}',
  1280. 'rule': function adFeedFilterRule(feed) {
  1281. if (!this.conf) return null;
  1282. return feed.getAttribute('feedtype') === 'ad' ? 'hidden' : null;
  1283. },
  1284. });
  1285.  
  1286. // 关注推荐微博
  1287. otherFilterGroup.add({
  1288. 'type': 'boolean',
  1289. 'key': 'weibo.other.fake_weibo',
  1290. 'text': '{{fakeWeiboFilterDesc}}',
  1291. 'rule': function fakeWeiboFilterRule(feed) {
  1292. if (!this.conf) return null;
  1293. if (!feed.getAttribute('mid')) return 'hidden';
  1294. return null;
  1295. },
  1296. });
  1297.  
  1298. // 已删除或没有权限查看的微博的转发
  1299. otherFilterGroup.add({
  1300. 'type': 'boolean',
  1301. 'key': 'weibo.other.deleted_forward',
  1302. 'text': '{{deletedForwardFilterDesc}}',
  1303. 'rule': function deletedForwardFilterRule(feed) {
  1304. if (!this.conf) return null;
  1305. if (feed.getAttribute('isforward') === '1' &&
  1306. !feed.querySelector('.WB_media_expand .WB_info .WB_name')) return 'hidden';
  1307. return null;
  1308. },
  1309. });
  1310.  
  1311. // 投票微博
  1312. otherFilterGroup.add({
  1313. 'type': 'boolean',
  1314. 'key': 'weibo.other.vote_weibo',
  1315. 'text': '{{voteWeiboFilterDesc}}',
  1316. 'rule': function voteWeiboFilterRule(feed) {
  1317. if (!this.conf) return null;
  1318. if (feed.querySelector('.WB_from a[href^="http://vote.weibo.com/"]'))
  1319. return 'hidden';
  1320. return null;
  1321. },
  1322. });
  1323.  
  1324. // 屏蔽隐藏微博
  1325. otherFilterGroup.add({
  1326. 'type': 'boolean',
  1327. 'key': 'weibo.other.block_hidden',
  1328. 'text': '{{blockHiddenWeiboDesc}}',
  1329. 'init': function () {
  1330. if (!this.conf) return;
  1331. addWeiboFilterListener(function (feed) {
  1332. [feed].concat(Array.apply(Array, feed.querySelectorAll('.WB_feed_type'))).forEach(function (feed) {
  1333. if (feed.getAttribute('yawf-display') !== 'hidden') return;
  1334. if (!feed.getAttribute('mid')) return;
  1335. blockWeibo(feed.getAttribute('mid'));
  1336. feed.setAttribute('yawf-block', 'block');
  1337. });
  1338. });
  1339. }
  1340. });
  1341.  
  1342. // 高亮显示白名单微博
  1343. otherFilterGroup.add({
  1344. 'type': 'boolean',
  1345. 'key': 'weibo.other.whitelist_highlight',
  1346. 'keys': { 'color': 'string' },
  1347. 'defaultcolor': '#fef3da',
  1348. 'text': '{{whitelistHighlightDesc}}',
  1349. 'shown': function (dom) {
  1350. var color = cewih('div', html.colorInput).firstChild;
  1351. color.value = this.getconfcolor();
  1352. color.addEventListener('change', function () {
  1353. this.putconfcolor(color.value);
  1354. }.bind(this));
  1355. dom.appendChild(color);
  1356. },
  1357. 'init': function () {
  1358. if (!this.conf) return;
  1359. css.add(fillStr(funcStr(function () { /*
  1360. [node-type="feed_list"] .WB_feed_type[yawf-display$="-show"] { background-color: {{color}} !important; box-shadow: -20px 0 0 {{color}}, 20px 0 0 {{color}}; }
  1361. [node-type="feed_list"] .WB_feed_together .WB_feed_type[yawf-display$="-show"] { background-color: {{color}} !important; box-shadow: -10px 0 0 {{color}}, 10px 0 0 {{color}}; }
  1362. */ }), { 'color': this.confcolor }));
  1363. },
  1364. });
  1365.  
  1366. // 添加数量和折叠/隐藏的
  1367. var lotShown = function (dom) {
  1368. var nl = cewih('label', fillStr(text.sameNumberOptionDesc, { 'number': html.numberInput }));
  1369. var sl = cewih('label', fillStr(text.sameActionOptionDesc, {
  1370. 'select': html.select,
  1371. 'options': fillStr(html.option, { 'value': 'fold', 'text': '{{foldlistActionDesc}}' }) +
  1372. fillStr(html.option, { 'value': 'hidden', 'text': '{{blacklistActionDesc}}' }),
  1373. }));
  1374. var n = nl.querySelector('input'), s = sl.querySelector('select');
  1375. n.setAttribute('min', '0');
  1376. n.value = this.getconfnumber();
  1377. n.addEventListener('change', function () { this.putconfnumber(Number(n.value)); }.bind(this));
  1378. s.value = this.getconfaction();
  1379. s.addEventListener('change', function () { this.putconfaction(s.value); }.bind(this));
  1380. dom.appendChild(nl); dom.appendChild(sl);
  1381. };
  1382.  
  1383. // 相同账号的过多微博
  1384. otherFilterGroup.add({
  1385. 'type': 'boolean',
  1386. 'priority': -1e6, // 低优先级
  1387. 'key': 'weibo.other.same_account',
  1388. 'keys': { 'number': 'number', 'action': 'string' },
  1389. 'defaultnumber': 5,
  1390. 'defaultaction': 'fold',
  1391. 'text': '{{sameAccountFilterDesc}}',
  1392. 'shown': lotShown,
  1393. 'rule': function sameAccountRule(feed) {
  1394. if (!this.conf) return null;
  1395. debug('RULE!: %o, %o', feed, this.getconf());
  1396. var author = feed.querySelector('.WB_name[usercard]');
  1397. if (!author) return null;
  1398. var id = author.getAttribute('usercard').split('=')[1];
  1399. var number = document.querySelectorAll('[node-type="feed_list"] ' +
  1400. '.WB_feed_type[yawf-display]:not([yawf-display$="-fold"]):not([yawf-display$="-unfold"]):not([yawf-display$="-hidden"])' +
  1401. '>.WB_feed_datail>.WB_detail>.WB_info>a.WB_name[usercard="id=' + id + '"]').length;
  1402. if (number >= this.confnumber) return 'account-' + this.confaction; else return null;
  1403. },
  1404. });
  1405.  
  1406. // 相同微博的过多转发
  1407. otherFilterGroup.add({
  1408. 'type': 'boolean',
  1409. 'priority': -1e6, // 低优先级
  1410. 'key': 'weibo.other.same_forward',
  1411. 'keys': { 'number': 'number', 'action': 'string' },
  1412. 'defaultnumber': 3,
  1413. 'defaultaction': 'fold',
  1414. 'text': '{{sameForwardFilterDesc}}',
  1415. 'shown': lotShown,
  1416. 'rule': function sameForwardRule(feed) {
  1417. if (!this.conf) return null;
  1418. var omid = feed.getAttribute('omid');
  1419. if (!omid) return null;
  1420. var number = document.querySelectorAll('[node-type="feed_list"] ' +
  1421. '.WB_feed_type[omid="' + omid + '"][yawf-display]:not([yawf-display$="-fold"]):not([yawf-display$="-unfold"]):not([yawf-display$="-hidden"])').length;
  1422. if (number >= this.confnumber) return 'forward-' + this.confaction; else return null;
  1423. },
  1424. });
  1425.  
  1426. var layoutFilterGroup = filterGroup('layoutFilterGroup');
  1427.  
  1428. layoutFilterGroup.add({
  1429. 'type': 'subtitle',
  1430. 'text': '{{layoutFilterGroupDesc}}',
  1431. });
  1432.  
  1433. // 大部分选择器参考了 眼不见心不烦 脚本
  1434. var layouts = (function () {
  1435. var current = null;
  1436. var subtitle = function (name) {
  1437. layoutFilterGroup.add({
  1438. 'type': 'subtitle',
  1439. 'text': '{{layoutHide' + name + '}}',
  1440. });
  1441. current = name;
  1442. };
  1443.  
  1444. var item = function (name, cssText, defaultValue) {
  1445. layoutFilterGroup.add({
  1446. 'type': 'boolean',
  1447. 'key': 'weibo.layoutHide' + current + name,
  1448. 'default': defaultValue || false,
  1449. 'text': '{{layoutHide' + current + name + '}}',
  1450. 'init': css(cssText),
  1451. });
  1452. };
  1453.  
  1454. subtitle('Icon');
  1455. item('Level', '.icon_bed[node-type="level"] { display: none !important; }');
  1456. item('Member', '.W_ico16[class*="ico_member"], .ico_member_dis { display: none !important; }');
  1457. item('Approve', '.approve { display: none !important; }');
  1458. item('ApproveCo', '.approve_co { display: none !important; }');
  1459. item('Club', '.ico_club { display: none !important; }');
  1460. item('VGirl', '.ico_vlady { display: none !important; }');
  1461. item('Taobao', '.ico_taobao { display: none !important; }');
  1462.  
  1463. subtitle('Nav');
  1464. item('Main', '.gn_nav>div:nth-child(1) { display: none !important; }');
  1465. item('App', '.gn_nav>div:nth-child(2) { display: none !important; }');
  1466. item('Hot', '.gn_nav>div:nth-child(3) { display: none !important; }');
  1467. item('Game', '.gn_nav>div:nth-child(4) { display: none !important; }');
  1468. item('Member', '.gn_setting[node-type="member"] { display: none !important; }');
  1469.  
  1470. subtitle('Left');
  1471. item('ToMe', '#pl_leftnav_common a[href^="/direct/tome"] { display: none !important; }');
  1472. item('Friends', '#pl_leftnav_group > div[node-type="groupList"] > .level_1_Box, #pl_leftnav_common .level_1_Box > form.left_nav_line { display: none !important; }');
  1473. item('App', '#pl_leftnav_app { display: none !important; }');
  1474.  
  1475. subtitle('Middle');
  1476. item('MemberTip', '[node-type="feed_list_shieldKeyword"] { display: none !important; }');
  1477. item('RecommendedTopic', '#pl_content_publisherTop div[node-type="recommendTopic"] { display: none !important; }');
  1478.  
  1479. subtitle('Right');
  1480. item('Whole', '.B_profile .W_main_c, .B_profile .WB_feed .repeat .input textarea { width: 100% } .B_profile .WB_feed .WB_screen { margin-left: 928px } .B_profile .W_main_2r { display: none !important; }');
  1481. item('Template', '#pl_content_setSkin { display: none !important; }');
  1482. item('Info', '.W_person_info { display: none !important; }');
  1483. item('Atten', '#pl_rightmod_myinfo .user_atten { display: none !important; }');
  1484. item('Trial', '#trustPagelet_checkin_lotteryv5 { display: none !important; }');
  1485. item('Interest', '[yawf-id="rightmod_recom_interest"] { display: none !important; }');
  1486. item('HotTopic', '[yawf-id="rightmod_zt_hottopic"] { display: none !important; }');
  1487. item('Member', '#trustPagelet_recom_memberv5 { display: none !important; }');
  1488. item('Weibo', '[yawf-id="rightmod_recom_weibo"] { display: none !important; }');
  1489. item('Location', '[yawf-id="rightmod_recom_location"] { display: none !important; }');
  1490. item('Music', '[yawf-id="rightmod_recom_music"] { display: none !important; }');
  1491. item('Movie', '[yawf-id="rightmod_recom_movie"] { display: none !important; }');
  1492. item('Book', '[yawf-id="rightmod_recom_book"] { display: none !important; }');
  1493. item('Notice', '#pl_rightmod_noticeboard { display: none !important; }');
  1494.  
  1495. subtitle('Weibo');
  1496. item('RecomFeed', '[node-type="feed_list_recommend"] { display: none !important; }');
  1497. item('TopicCard', '.WB_feed_spec[exp-data*="value=1022-topic"] { display: none !important; }');
  1498. item('LocationCard', '.WB_feed_spec[exp-data*="value=1022-place"] { display: none !important; }');
  1499. item('FeedTip', '[node-type="feed_privateset_tip"] { display: none !important; }');
  1500.  
  1501. subtitle('Person');
  1502. item('Cover', '.profile_pic_top { max-height: 120px; }');
  1503. item('Template', '.templete_enter { display: none !important; }');
  1504. item('BadgeIcon', '.pf_badge_icon { display: none !important; }');
  1505. item('Stats', '.profile_top .user_atten { display: none !important; } .pf_head { margin-top: 51px; } ');
  1506. item('MyData', '.W_main_c [id^="Pl_Official_MyMicroworld__"] { display: none !important; }');
  1507. item('Group', '.W_main_2r [id^="Pl_Core_RightGroupsBtn__"] { display: none !important; }');
  1508. item('SuggestUser', '.W_main_2r [id^="Pl_Core_RightUserList__"] { display: none !important; }');
  1509. item('Relation', '.W_main_2r [id^="Pl_Core_RightUserGrid__"] { display: none !important; }');
  1510. item('Album', '.W_main_2r [id^="Pl_Core_RightPicMulti__"] { display: none !important; }'); // FIXME
  1511. item('HotTopic', '.W_main_2r [id^="Pl_Core_RightTextSingle__"] { display: none !important; }');
  1512. item('HotWeibo', '.W_main_2r [id^="Pl_Core_RightPicText__"] { display: none !important; }');
  1513.  
  1514. subtitle('Other');
  1515. item('Ads', '#plc_main [id^="pl_rightmod_ads"], #Box_right [id^="ads_"], #trustPagelet_zt_hottopicv5 [class*="hot_topicad"], div[ad-data], .WB_feed .popular_buss, [id^="sinaadToolkitBox"] { display: none !important; } #wrapAD, .news_logo { visibility: hidden !important; }');
  1516. item('FeedRecom', '.W_main_2r [id^="Pl_Third_Inline__"] { display: none !important; }');
  1517. item('Footer', '.global_footer { display: none !important; }');
  1518. item('WbIm', '.WBIM_news { display: none !important; }');
  1519. item('Tip', '.layer_tips { display: none !important; }');
  1520.  
  1521. var tagRightbarMods = function () {
  1522. var mods = document.querySelectorAll('#trustPagelet_indexright_recom .WB_right_module:not([yawf-id])');
  1523. if (!mods) return;
  1524. var identifiers = {
  1525. '.right_content.hot_topic': 'rightmod_zt_hottopic',
  1526. '.right_content.person_list': 'rightmod_recom_interest',
  1527. '[change-data*="key=index_weibo"]': 'rightmod_recom_weibo',
  1528. '[change-data*="key=index_LBS"]': 'rightmod_recom_location',
  1529. '[change-data*="key=index_song"]': 'rightmod_recom_music',
  1530. '[change-data*="key=index_mov"]': 'rightmod_recom_movie',
  1531. '[change-data*="key=index_book"]': 'rightmod_recom_book'
  1532. };
  1533. Array.apply(Array, mods).forEach(function (mod) {
  1534. Object.keys(identifiers).forEach(function (qs) {
  1535. if (mod.querySelector(qs)) mod.setAttribute('yawf-id', identifiers[qs]);
  1536. });
  1537. });
  1538. };
  1539.  
  1540. newNode.add(tagRightbarMods);
  1541. tagRightbarMods();
  1542. css.add('.W_miniblog { visibility: visible !important; }');
  1543.  
  1544. }());
  1545.  
  1546. // 改造设置
  1547. var toolFilterGroup = filterGroup('toolFilterGroup');
  1548.  
  1549. // 清除发布框中的默认话题 (wcf)
  1550. toolFilterGroup.add({
  1551. 'type': 'boolean',
  1552. 'key': 'weibo.tool.clear_def_topic',
  1553. 'text': '{{clearDefTopicDesc}}',
  1554. 'init': function () {
  1555. if (!this.conf) return;
  1556. var clearDefTopic = function () {
  1557. var inputBox = document.querySelector('#pl_content_publisherTop .send_weibo .input textarea');
  1558. if (inputBox && inputBox.hasAttribute('hottopic')) {
  1559. inputBox.removeAttribute('hottopic'); inputBox.removeAttribute('hottopicid');
  1560. inputBox.value = 'DUMMY'; inputBox.focus();
  1561. inputBox.value = ''; inputBox.blur();
  1562. }
  1563. };
  1564. newNode.add(clearDefTopic);
  1565. },
  1566. });
  1567.  
  1568. // 展开左栏分组
  1569. toolFilterGroup.add({
  1570. 'type': 'boolean',
  1571. 'key': 'weibo.tool.showAllGroup',
  1572. 'text': '{{showAllGroupDesc}}',
  1573. 'init': css('#pl_leftnav_group div[node-type="moreList"] { display: block !important } #pl_leftnav_group > div[node-type="groupList"] > .level_2_Box > .levmore { display: none }'),
  1574. });
  1575.  
  1576. // 展开左栏消息
  1577. toolFilterGroup.add({
  1578. 'type': 'boolean',
  1579. 'key': 'weibo.tool.showAllMsgNav',
  1580. 'text': '{{showAllMsgNavDesc}}',
  1581. 'init': css('#pl_leftnav_common > .level_1_Box > .lev2_new { display: block !important }'),
  1582. });
  1583.  
  1584. // 微博作者与正文同行
  1585. toolFilterGroup.add({
  1586. 'type': 'boolean',
  1587. 'key': 'weibo.tool.unwrapText',
  1588. 'text': '{{unwrapTextDesc}}',
  1589. 'init': css('.WB_info, .WB_text { display: inline } .WB_info+.WB_text::before { content: ": " } .WB_func { margin-top: 5px } .B_index .WB_feed .W_ico16 { vertical-align: -3px !important }'),
  1590. });
  1591.  
  1592. // 查看大图旁添加查看原图链接
  1593. toolFilterGroup.add({
  1594. 'type': 'boolean',
  1595. 'default': true,
  1596. 'key': 'weibo.tool.viewOriginal',
  1597. 'text': '{{viewOriginalDesc}}',
  1598. 'init': function () {
  1599. if (!this.conf) return;
  1600. var addOriLink = function () {
  1601. var a = document.querySelector('a.show_big[action-data]:not([yawf-viewori])');
  1602. if (!a) return; a.setAttribute('yawf-viewori', 'yawf-viewori');
  1603. var arg = a.getAttribute('action-data').match(/pid=(\w+)&mid=(\d+)&uid=(\d+)/);
  1604. if (!arg) return;
  1605. var vol = cewih('div', fillStr(html.viewOriginalLink)), l = vol.firstChild;
  1606. var img = fillStr(url.view_ori, { 'uid': arg[3], 'mid': arg[2], 'pid': arg[1] });
  1607. while (vol.firstChild) a.parentNode.insertBefore(vol.firstChild, a);
  1608. if (0) GM_xmlhttpRequest({
  1609. 'method': 'GET',
  1610. 'url': img,
  1611. 'onload': function (resp) {
  1612. var h = (new DOMParser()).parseFromString(resp.responseText, 'text/html');
  1613. l.href = h.querySelector('#pic').src;
  1614. },
  1615. }); l.href = img;
  1616. };
  1617. newNode.add(addOriLink);
  1618. },
  1619. });
  1620.  
  1621. // 自定义样式
  1622. toolFilterGroup.add({
  1623. 'type': 'string',
  1624. 'text': '{{userstyleTitle}}',
  1625. 'key': 'weibo.tool.userstyle',
  1626. 'init': function () {
  1627. var conf = this.conf; GM_addStyle(conf);
  1628. var set = this.putconf.bind(this);
  1629. var putconf = function (css) {
  1630. conf = css;
  1631. setTimeout(function () { set(css); config.write(); location.reload(); }, 0);
  1632. };
  1633. GM_registerMenuCommand(fillStr('{{userstyleEditDesc}}'), function () {
  1634. var newcss = prompt(fillStr('{{userstyleEditDetails}}'), conf);
  1635. if (newcss !== null) putconf(newcss);
  1636. }, "S");
  1637. },
  1638. });
  1639.  
  1640.  
  1641. // 脚本设置
  1642. var scriptFilterGroup = filterGroup('scriptFilterGroup');
  1643.  
  1644. // 导入导出
  1645. scriptFilterGroup.add({
  1646. 'type': 'subtitle',
  1647. 'text': '{{configImportAndExport}}',
  1648. });
  1649.  
  1650. scriptFilterGroup.add({
  1651. 'show': function () {
  1652. var dom = cewih('div', html.configImportExport).firstChild;
  1653. var bii = dom.querySelector('input[type="file"]');
  1654. var be = dom.querySelector('[node-type="export"]');
  1655. var br = dom.querySelector('[node-type="reset"]');
  1656. // 导出按钮
  1657. var updateExportButton = function () {
  1658. be.href = 'data:application/octet-stream;base64,' +
  1659. btoa(unescape(encodeURIComponent(config.export())));
  1660. be.setAttribute('download', 'yawf-config.yawf');
  1661. };
  1662. // 导入按钮
  1663. var doImport = function (file) {
  1664. var reader = new FileReader();
  1665. var success = function () {
  1666. Alert('yawf-config-import-success', {
  1667. 'title': fillStr('{{configImportSuccessTitle}}'),
  1668. 'text': fillStr('{{configImportSuccess}}'),
  1669. 'icon': 'succ'
  1670. });
  1671. };
  1672. var error = function () {
  1673. Alert('yawf-config-import-fail', {
  1674. 'title': fillStr('{{configImportFailTitle}}'),
  1675. 'text': fillStr('{{configImportFail}}'),
  1676. 'icon': 'error'
  1677. });
  1678. };
  1679. if (file.size > (1 << 24)) error();
  1680. else reader.addEventListener('load', function () {
  1681. if (config.import(reader.result)) {
  1682. updateExportButton();
  1683. success();
  1684. } else error();
  1685. });
  1686. reader.readAsText(file);
  1687. bii.value = '';
  1688. };
  1689. bii.addEventListener('change', function () {
  1690. var file = bii.files[0];
  1691. Confirm('yawf-config-import-warning', {
  1692. 'title': fillStr('{{configImportWarningTitle}}'),
  1693. 'text': fillStr('{{configImportWarning}}'),
  1694. 'onOk': function () { doImport(file); },
  1695. });
  1696. });
  1697. updateExportButton();
  1698. // 重置按钮
  1699. var doReset = function () {
  1700. config.clear();
  1701. updateExportButton();
  1702. };
  1703. br.addEventListener('click', function () {
  1704. Confirm('yawf-config-reset-warning', {
  1705. 'title': fillStr('{{configResetWarningTitle}}'),
  1706. 'text': fillStr('{{configResetWarning}}'),
  1707. 'onOk': doReset,
  1708. });
  1709. });
  1710. return dom;
  1711. },
  1712. });
  1713.  
  1714. // 调试
  1715. scriptFilterGroup.add({
  1716. 'type': 'subtitle',
  1717. 'text': '{{scriptDebugTitle}}',
  1718. });
  1719.  
  1720. scriptFilterGroup.add({
  1721. 'show': function () {
  1722. var dom = cewih('div', fillStr(html.configBoolean, { 'key': 'debug', 'text': '{{scriptDebug}}' })).firstChild;
  1723. var input = dom.querySelector('input');
  1724. input.checked = !!GM_getValue('debug', false);
  1725. input.addEventListener('change', function () {
  1726. GM_setValue('debug', !GM_getValue('debug', false));
  1727. });
  1728. return dom;
  1729. }
  1730. });
  1731.  
  1732. // 关于
  1733. scriptFilterGroup.add({
  1734. 'type': 'subtitle',
  1735. 'text': '{{scriptAboutTitle}}',
  1736. });
  1737.  
  1738. scriptFilterGroup.add({
  1739. 'type': 'text',
  1740. 'text': '{{scriptAbout}}',
  1741. });
  1742.  
  1743. scriptFilterGroup.add({
  1744. 'init': function () {
  1745. var isEn = i18n.lang === 'en';
  1746. css.add(fillStr(funcStr(function () { /*!CSS
  1747. .profile_tab .pftb_lk { padding-left: {{headerWidth}}; padding-right: {{headerWidth}}; }
  1748. .profile_tab .current.pftb_lk { padding-left: {{headerWidth2}}; padding-right: {{headerWidth2}}; }
  1749. .layoutFilterGroupLayer .yawf-configBoolean { width: {{layoutOptionWidth}}; }
  1750. */ }), {
  1751. 'headerWidth': isEn ? '12px' : '15px',
  1752. 'headerWidth2': isEn ? '9px' : '12px',
  1753. 'layoutOptionWidth': isEn ? '320px' : '160px',
  1754. }));
  1755. },
  1756. });
  1757.  
  1758. // 检查是否要在本页上运行
  1759. var validPage = function () {
  1760. if (self !== top) return false;
  1761. if (!unsafeWindow.$CONFIG.uid) return false;
  1762. if (!unsafeWindow.$CONFIG.lang) return false;
  1763. return true;
  1764. };
  1765.  
  1766. // 完成加载时
  1767. var dcl = function () {
  1768. if (!validPage()) return;
  1769. // 初始化用户语言
  1770. i18n.setLang(unsafeWindow.$CONFIG.lang);
  1771. // 加载用户配置
  1772. config = config(unsafeWindow.$CONFIG.uid);
  1773. typedConfig();
  1774. // 初始化文本和网页数据(基于用户选择的语言)
  1775. Object.keys(text).map(function (key) { i18n(text[key]); text[key] = text[key].local; });
  1776. Object.keys(html).map(function (key) { html[key] = fillStr(html[key]); });
  1777. // 初始化所有过滤器
  1778. filters.init();
  1779. // 初始化折叠微博
  1780. fixFoldWeibo.init();
  1781. // 注册样式
  1782. css.init();
  1783. // 显示设置按钮
  1784. showIcon();
  1785. // 开始过滤
  1786. newNode.active();
  1787. };
  1788. if (document.body) call(dcl);
  1789. else document.addEventListener('DOMContentLoaded', dcl);
  1790.  
  1791. GM_addStyle(fillStr((funcStr(function () { /*!CSS
  1792. // 在顶部添加按钮
  1793. .gn_setting[node-type="member"]:last-child { margin-right: 44px; }
  1794. .WB_global_nav .gn_setting .gn_tab.gn_filter .ico { background-image: url("{{filter-img}}"); !important; background-position: 0 0 !important; }
  1795. .WB_global_nav .gn_search { width: 210px !important; left: 440px !important; position: absolute !important; }
  1796. .WB_global_nav .gn_search .gn_input { width: 168px !important; }
  1797. // 设置框相关样式
  1798. .yawf-Layer.yawf-drag { opacity: 0.67; -moz-user-select: none; user-select: none; }
  1799. #yawf-config [node-type="inner"] { padding: 20px; }
  1800. .yawf-config-body { margin: -20px -20px 0; max-height: 300px; overflow-y: auto; padding: 20px; width: 760px; }
  1801. #yawf-config .profile_tab { font-size: 12px; margin: -20px -20px 20px; width: 800px; }
  1802. .yawf-groupSubtitle { margin: 5px 10px; padding: 10px 0 0 0; font-weight: bold; }
  1803. .yawf-configItem, .yawf-groupText { margin: 5px 20px; padding: 5px 0; }
  1804. .yawf-configString span { line-height: 16px; padding: 2px 10px; margin-bottom: -20px; display: block; width: calc(100% - 20px); position: relative; }
  1805. .yawf-configString textarea.W_input { width: calc(100% - 20px); padding-top: 20px; min-height: 80px; resize: vertical; }
  1806. .yawf-configStringsInput, .yawf-configUsersInput { margin: 5px; }
  1807. .yawf-configStringsItems, .yawf-configUsersItems { padding: 5px 10px; }
  1808. .yawf-configStringsItem, .yawf-configUsersItem { display: inline-block; margin: 2px; }
  1809. .yawf-configStringsItem a.icon_close, .yawf-configUsersItem a.icon_close { margin-left: 3px; vertical-align: -2px; }
  1810. .yawf-configUsersItem .shield_object_card { display: inline-block; }
  1811. .yawf-configUsersItem .shield_object_card .card_bg { border: 1px solid #e6e6e6; border-radius: 2px; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.02); padding: 1px 5px 1px 1px; }
  1812. .yawf-configUsersItem .shield_object_card .card_pic { float: left; width: 50px; }
  1813. .yawf-configUsersItem .shield_object_card .card_pic .pic_box { display: block; }
  1814. .yawf-configUsersItem .shield_object_card .card_content { margin-left: 60px; }
  1815. .yawf-configUsersItem .shield_object_card .object_info { height: 22px; margin-top: 2px; }
  1816. .yawf-configUsersItem .shield_object_card .object_name { line-height: 22px; overflow: hidden; }
  1817. .yawf-configUsersItem .shield_object_card .other_info { line-height: 24px; }
  1818. .yawf-configImportExport [node-type] { margin-right: 20px; }
  1819. .yawf-configAdd { appearance: none; }
  1820. #yawf-config .btn { border-top: 1px solid #ccc; margin: 15px 0 0; padding: 10px 0 0; }
  1821. #yawf-config .btn .W_btn_b_disable:hover { border-color: #d9d9d9; }
  1822. #yawf-config .btn .W_btn_b_disable:hover span { border-color: #ffffff; }
  1823. .layoutFilterGroupLayer .yawf-configBoolean { display: inline-block; margin-right: 0; }
  1824. // 隐藏微博
  1825. [yawf-display$="-hidden"] { display: none !important; }
  1826. [node-type="feed_list"] .WB_feed_type:not([yawf-display]), [node-type="feed_list"] .WB_feed_type .WB_feed_type:not([yawf-display]) { visibility: hidden !important; }
  1827. // 折叠微博
  1828. [node-type="feed_list"] .WB_feed_type[yawf-display$="-fold"]::before { display: block; width: 100%; height: 24px; line-height: 24px; padding: 0 2em 20px; border-bottom: #e6e6e6 1px solid; }
  1829. [node-type="feed_list"] .WB_feed_type[yawf-display$="-fold"] { height: 45px; overflow: hidden; cursor: pointer; }
  1830. [node-type="feed_list"] .WB_feed_type[yawf-display$="-fold"] .WB_screen { margin-top: -40px !important; }
  1831. [node-type="feed_list"] .WB_feed_type[yawf-display$="-fold"] .WB_feed_datail { display: none !important; }
  1832. // 子微博
  1833. [node-type="feed_list"] .WB_feed_type[yawf-display$="-hidden"]+.WB_feed_type[yawf-display$="-son"],
  1834. [node-type="feed_list"] .WB_feed_type[yawf-display$="-fold"]+.WB_feed_type[yawf-display$="-son"] { display: none !important; }
  1835. [node-type="feed_list"] .WB_feed_type:not([yawf-display$="-son"]) .WB_feed_together { display: none !important; }
  1836. [node-type="feed_list"] .WB_feed_type[yawf-withson="son"] .WB_feed_datail,
  1837. [node-type="feed_list"] .WB_feed_type[yawf-withson="son"][yawf-display$="-fold"]::before { border: 0 none !important; }
  1838. [node-type="feed_list"] .WB_feed_type[yawf-display$="-son"] { padding-top: 0 !important; }
  1839. [node-type="feed_list"] .WB_feed_type[yawf-display$="-son"]>.WB_screen,
  1840. [node-type="feed_list"] .WB_feed_type[yawf-display$="-son"]>.WB_feed_datail>.WB_face,
  1841. [node-type="feed_list"] .WB_feed_type[yawf-display$="-son"]>.WB_feed_datail>.WB_detail>*:not(.WB_feed_together) { display: none !important; }
  1842. [node-type="feed_list"] .WB_feed_type[yawf-display$="-son"]>.WB_feed_datail>.WB_detail { margin-top: -20px; margin-bottom: -10px; }
  1843. // 其他
  1844. .WB_feed_together .wft_users { display: none; }
  1845. .WB_feed_together[yawf-sonfold="display"] [node-type="feed_list_wrapForward"] { display: block !important; }
  1846. .WB_feed_together[yawf-sonfold="display"] [action-type="feed_list_seeAll"],
  1847. .WB_feed_together[yawf-sonfold="display"] [action-type="feed_list_foldForward"] { display: none !important; }
  1848. .W_miniblog { visibility: hidden; }
  1849. */ }) + '\n').replace(/\/\/.*\n/g, '\n'), {
  1850. 'filter-img': images.filter,
  1851. }));