MaiJZ-AcFun小助手

文章区:评论区域居中、文章内容始终显示、高亮楼主名字;视频:在简介栏中可以显示封面;

  1. // ==UserScript==
  2. // @name MaiJZ-AcFun小助手
  3. // @namespace https://github.com/maijz128
  4. // @version 22.11.13
  5. // @description 文章区:评论区域居中、文章内容始终显示、高亮楼主名字;视频:在简介栏中可以显示封面;
  6. // @author MaiJZ
  7. // @match *://*.acfun.cn/*
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @grant GM_cookie
  11. // @grant GM.cookie
  12. // @grant GM_setClipboard
  13. // @grant GM_xmlhttpRequest
  14. // @grant unsafeWindow
  15. // @grant window.close
  16. // @grant window.focus
  17. // ==/UserScript==
  18.  
  19.  
  20. (function () {
  21. setTimeout(function () {
  22. main();
  23. }, 10);
  24. })();
  25.  
  26.  
  27. function main() {
  28. if (matchURL("/a/ac")) {
  29. //Article();
  30. } else if (matchURL("/v/ac")) {
  31. VideoPage();
  32. VideoTitle();
  33. } else if (matchURL("live.acfun")) {
  34. //LivePage();
  35. } else if (isHomePage()) {
  36. //HomePage();
  37. } else if (IsImage()) {
  38. AcFunImage();
  39. }
  40. }
  41.  
  42.  
  43. // 首页
  44.  
  45. function isHomePage() {
  46. var href = window.location.href;
  47. return href === 'http://www.acfun.cn/' || href === 'https://www.acfun.cn/';
  48. }
  49.  
  50.  
  51.  
  52. function HomePage() {
  53.  
  54. }
  55.  
  56. //直播
  57. function LivePage() {
  58. // 删除TV
  59. var tv = document.querySelector('.tv-wrapper');
  60. if (tv) {
  61. tv.remove();
  62. }
  63. }
  64.  
  65. // 视频
  66. function VideoPage() {
  67.  
  68. // 观影模式时:输入弹幕栏改变CSS
  69. var style = ".container-player[data-bind-attr='web'] .container-video .container-plugins-inner .container-controls .control-bar-bottom, .container-player[data-bind-attr='screen'] .container-video .container-plugins-inner .container-controls .control-bar-bottom, .container-player.film-mode .container-video .container-plugins-inner .container-controls .control-bar-bottom";
  70. style += "{left: 180px !important; }";
  71. addStyle(style);
  72.  
  73. var coverURL = getVideoCoverURL();
  74. //addCoverLink(coverURL);
  75. console.log('Cover URL');
  76. console.log(coverURL);
  77.  
  78. // 自动宽屏播放
  79. setTimeout(function () {
  80. var btn = document.querySelector('.film-model .btn-film-model');
  81. if (btn) {
  82. eventFire(btn, 'click');
  83. }
  84. }, 2000);
  85.  
  86.  
  87. function addCoverLink(url) {
  88. var style = '.video-cover:hover img { display: block !important; }';
  89. style += '.video-cover img { position: absolute; z-index: 99; }';
  90. addStyle(style);
  91.  
  92. var elTitle = document.querySelector("#main div.introduction section div.title");
  93. if (elTitle) {
  94. var strHtml = '<span style="margin-right: 20px;">简介</span>';
  95. strHtml += '<span class="video-cover"> <a href="' + url + '" target="_blank">封面</a>';
  96. strHtml += '<img src="' + url + '" style="display: none;">';
  97. strHtml += '</span>';
  98.  
  99. elTitle.innerHTML = strHtml;
  100. }
  101. }
  102.  
  103.  
  104. function getVideoCoverURL() {
  105. var result = null;
  106. // var player = document.getElementById("ACFlashPlayer");
  107. var pageInfo = document.querySelector('#main #pageInfo');
  108. if (pageInfo) {
  109. var value = pageInfo.getAttribute('data-pic');
  110. result = value;
  111. }
  112. return result;
  113. }
  114. }
  115.  
  116. function VideoTitle(){
  117. // var titleDiv = $("#main-content div.video-description h1.title");
  118. var titleDiv = document.querySelector("#main-content div.video-description h1.title");
  119. if (titleDiv) {
  120. var btn = document.createElement("button");
  121. btn.textContent = "复制";
  122. btn.onclick = function(){
  123. var title = document.querySelector("h1.title span").innerHTML;
  124. console.log(title);
  125. GM_setClipboard(title);
  126. };
  127. titleDiv.appendChild(btn);
  128. }
  129. }
  130.  
  131.  
  132. // 文章
  133. function Article() {
  134. this.upId = null;
  135. this.upName = null;
  136. this.time = null;
  137.  
  138. this._init = function () {
  139. var elArticleUp = document.getElementById('article-up');
  140. var elUpName = elArticleUp.querySelector('.up-name a');
  141. this.upName = elUpName.innerHTML;
  142.  
  143. var href = elUpName.getAttribute('href');
  144. this.upId = href.replace('/u/', '').replace('.aspx', '');
  145.  
  146. var elTime = elArticleUp.querySelector('.up-time');
  147. this.time = elTime.innerHTML;
  148.  
  149.  
  150. //var style = '.display-block{display: block !important;}';
  151. // style += '.comment-content{width: 850px !important; margin: 0 auto !important;}';
  152. // addStyle(style);
  153.  
  154. };
  155.  
  156. // 高亮楼主名字
  157. this.highlightUp = function () {
  158. var COLOR = "#008000";
  159. var style = 'a[data-uid="' + this.upId + '"]{';
  160. style += 'color: ' + COLOR + ' !important;';
  161. style += 'font-weight: bold !important;}';
  162.  
  163. // 楼主标志
  164. style += 'a[data-uid="' + this.upId + '"]:before {';
  165. // 样式1
  166. // style += 'content: "UP: "; color: #c66;';
  167. // 样式2
  168. style += 'content: "UP主"; padding: 1px 2px; margin-right: 4px; font-size: 12px; background-color: #4a8eff; border-radius: 2px; color: #fff;';
  169. style += '}';
  170.  
  171. addStyle(style);
  172. };
  173.  
  174. // 在查看下一页评论时,文章内容也一直显示
  175. this.alwaysShowContent = function () {
  176. $('#article-content').addClass('display-block');
  177. };
  178.  
  179. // 让评论区域居中显示
  180. this.centerComments = function () {
  181. var style = '.columen-left { width: 850px !important; padding-top: 20px;';
  182. style += 'float: none !important; margin: 0 auto !important; }';
  183. addStyle(style);
  184. };
  185.  
  186. // 评论区域元素上移
  187. this.moveUpComments = function () {
  188. var contentArea = $('.content:first');
  189. var elCommentArea = $('.comment-area:first');
  190. contentArea.append(elCommentArea);
  191. };
  192.  
  193. // 文章内容
  194. this.articleContent = function () {
  195. var style = '#article-content>.article-content { min-height: 400px; }';
  196. addStyle(style);
  197. };
  198.  
  199. this._init();
  200. this.highlightUp();
  201. //this.alwaysShowContent();
  202. this.centerComments();
  203. this.moveUpComments();
  204. this.articleContent();
  205. }
  206.  
  207.  
  208. function IsImage(){
  209. if (matchURL("/kimg/") || matchURL("image/resize")) {
  210. return true;
  211. }
  212. return false;
  213. }
  214. function AcFunImage(){
  215. if ( matchURL("image/resize")) {
  216. var href = window.location.href;
  217. var newhref = href.split("?")[0];
  218. window.location.href = newhref;
  219. }
  220. }
  221.  
  222.  
  223. //########################################################################
  224.  
  225.  
  226. function matchURL(url) {
  227. const URL = window.location.href;
  228. return URL.indexOf(url) > -1;
  229. }
  230.  
  231. function addStyle(styleContent) {
  232. var elStyle = document.createElement("style");
  233. elStyle.innerHTML = styleContent;
  234. document.head.appendChild(elStyle);
  235. }
  236.  
  237. // Usage: fireKeyEvent(input元素, 'keydown', 13);
  238. // http://blog.csdn.net/lovelyelfpop/article/details/52471878
  239. function fireKeyEvent(el, evtType, keyCode) {
  240. var doc = el.ownerDocument;
  241. var win = doc.defaultView || doc.parentWindow,
  242. evtObj;
  243. if (doc.createEvent) {
  244. if (win.KeyEvent) {
  245. evtObj = doc.createEvent('KeyEvents');
  246. evtObj.initKeyEvent(evtType, true, true, win, false, false, false, false, keyCode, 0);
  247. } else {
  248. evtObj = doc.createEvent('UIEvents');
  249. Object.defineProperty(evtObj, 'keyCode', {
  250. get: function () {
  251. return this.keyCodeVal;
  252. }
  253. });
  254. Object.defineProperty(evtObj, 'which', {
  255. get: function () {
  256. return this.keyCodeVal;
  257. }
  258. });
  259. evtObj.initUIEvent(evtType, true, true, win, 1);
  260. evtObj.keyCodeVal = keyCode;
  261. if (evtObj.keyCode !== keyCode) {
  262. console.log("keyCode " + evtObj.keyCode + " 和 (" + evtObj.which + ") 不匹配");
  263. }
  264. }
  265. el.dispatchEvent(evtObj);
  266. } else if (doc.createEventObject) {
  267. evtObj = doc.createEventObject();
  268. evtObj.keyCode = keyCode;
  269. el.fireEvent('on' + evtType, evtObj);
  270. }
  271. }
  272.  
  273. function eventFire(el, eType) {
  274. if (el.fireEvent) {
  275. el.fireEvent('on' + eType);
  276. } else {
  277. var evObj = document.createEvent('Events');
  278. evObj.initEvent(eType, true, false);
  279. el.dispatchEvent(evObj);
  280. }
  281. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址