Yet Another Weibo Filter

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

当前为 2014-07-15 提交的版本,查看 最新版本

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