YouTube Click To Play

它禁用自动播放,并启用点击播放。

当前为 2020-07-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Click To Play
  3. // @name:ja YouTube Click To Play
  4. // @name:zh-CN YouTube Click To Play
  5. // @namespace knoa.jp
  6. // @description It disables autoplay and enables click to play.
  7. // @description:ja 自動再生を無効にし、クリックで再生するようにします。
  8. // @description:zh-CN 它禁用自动播放,并启用点击播放。
  9. // @include https://www.youtube.com/*
  10. // @noframes
  11. // @run-at document-start
  12. // @grant none
  13. // @version 1.1.1
  14. // ==/UserScript==
  15.  
  16. (function(){
  17. const SCRIPTID = 'YouTubeClickToPlay';
  18. const SCRIPTNAME = 'YouTube Click To Play';
  19. const DEBUG = true;/*
  20. [update] 1.1.1
  21. fix for thumbnails.
  22.  
  23. [bug]
  24.  
  25. [todo]
  26.  
  27. [possible]
  28. t=n 指定があればむしろサムネではなくその時点の映像にしてあげる?
  29. 0秒で常にサムネに戻る仕様?(seekingイベントでよい)
  30. channel/ と watch/ は個別に設定可能とか
  31. => channelだけで動作する別スクリプトがある
  32. document.hidden でのみ作動するオプションとか
  33.  
  34. [research]
  35. シアターモードの切り替えで再生してしまう件(そこまで気にしなくてもいい気もする)
  36.  
  37. [memo]
  38. 本スクリプト仕様:
  39. サムネになってほしい: チャンネルホーム, ビデオページ
  40. 再生してほしい: LIVE, 広告, 途中広告からの復帰
  41. 要確認: 各ページの行き来, 再生で即停止しないこと, シアターモードの切り替え, 背面タブでの起動
  42. (YouTubeによるあっぱれなユーザー体験の追究のおかげで、初回読み込み時に限り再生開始済みのvideo要素が即出現する)
  43. YouTube仕様:
  44. 画面更新(URL Enter, S-Reload, Reload に本質的な差異なし)
  45. 新規タブ(開いた直後, 読み込み完了後, title変更後 に本質的な差異なし)
  46. video: body ... video ... loadstart ... で必ず play() されるのでダミーと入れ替えておけばよい。
  47. video要素は #player-api 内に出現した後に ytd-watch-flexy 内に移動する。その際に play() されるようだ。
  48. t=123 のような時刻指定があると seeking 後にもう一度 play() される。
  49. thumbnail は t=4 以下だとなぜか消えてしまう。(seekじゃなくてadvanceだとみなされるせい?)
  50. channel: body ... video ... loadstart で即 pause() 可能。(playは踏まれない)
  51. 画面遷移(動画 <=> LIVE <=> チャンネル)
  52. video: yt-navigate-start ... loadstart で即 pause() 可能。(playは踏まれない)
  53. 広告
  54. 冒頭広告: .ad-showing 依存だが判定できる。
  55. 広告明け: 少しだけ泥臭いが、そのURLで一度でも本編が再生されていれば広告明けとみなす。
  56. 広告が入ると広告のサムネイルがセットされた状態になるので、独自にセットしなければならない。
  57. Firefoxなどのブラウザが動画の自動再生をくい止めた場合に備えて広告のサムネイルになると推測。
  58. 参考:
  59. Channelトップの動画でのみ機能するスクリプト
  60. https://greasyfork.org/ja/scripts/399862-kill-youtube-channel-video-autoplay
  61. */
  62. if(window === top && console.time) console.time(SCRIPTID);
  63. const MS = 1, SECOND = 1000*MS, MINUTE = 60*SECOND, HOUR = 60*MINUTE, DAY = 24*HOUR, WEEK = 7*DAY, MONTH = 30*DAY, YEAR = 365*DAY;
  64. const FLAGNAME = SCRIPTID.toLowerCase();
  65. const site = {
  66. get: {
  67. moviePlayer: () => $('#movie_player'),
  68. spinner: () => $('.ytp-spinner'),
  69. video: () => $(`video:not([data-${FLAGNAME}])`),
  70. videoId: (url) => (new URL(url)).searchParams.get('v'),
  71. startTime: () => {
  72. /* t=1h0m0s or t=3600 */
  73. let t = (new URL(location.href)).searchParams.get('t');
  74. if(t === null) return;
  75. let [h, m, s] = t.match(/^(?:([0-9]+)h)?(?:([0-9]+)m)?(?:([0-9]+)s?)?$/).slice(1).map(n => parseInt(n || 0));
  76. return 60*60*h + 60*m + s;
  77. },
  78. },
  79. is: {
  80. immediate: (video) => $('#player-api', player => player.contains(video)),
  81. live: () => $('.ytp-time-display.ytp-live') !== null,
  82. ad: () => $('#movie_player.ad-showing') !== null,
  83. list: () => (new URL(location)).searchParams.get('list') !== null,
  84. autoplay: () => $('ytd-watch-next-secondary-results-renderer paper-toggle-button.ytd-compact-autoplay-renderer', button => button.checked),
  85. },
  86. views: {
  87. channel: {
  88. url: /^https:\/\/www\.youtube\.com\/(channel|c|user)\//,
  89. get: {
  90. thumbnailOverlayImage: () => $('.ytp-cued-thumbnail-overlay-image'),
  91. thumbnailURL: () => THUMBNAILURL.replace('{id}', view.get.videoId()),
  92. videoId: () => $('a.ytp-title-link[href]', a => site.get.videoId(a.href)),
  93. },
  94. },
  95. watch: {
  96. url: /^https:\/\/www\.youtube\.com\/watch\?/,
  97. get: {
  98. thumbnailOverlayImage: () => $('.ytp-cued-thumbnail-overlay-image'),
  99. thumbnailURL: () => THUMBNAILURL.replace('{id}', view.get.videoId()),
  100. videoId: () => site.get.videoId(location.href),
  101. upnextId: () => $('ytd-compact-autoplay-renderer a[href]', a => site.get.videoId(a.href)),
  102. playlistAutoplayInsertBefore: () => $('ytd-watch-flexy #playlist-actions #save-button'),
  103. autoplayLabel: () => $('#upnext + #autoplay'),
  104. },
  105. },
  106. },
  107. };
  108. let elements = {}, flags = {}, view;
  109. const core = {
  110. initialize: function(){
  111. elements.html = document.documentElement;
  112. elements.html.classList.add(SCRIPTID);
  113. core.findVideo();
  114. core.addStyle('style');
  115. },
  116. findVideo: function(){
  117. const found = function(video){
  118. //log(video);
  119. if(video.dataset[FLAGNAME]) return;
  120. video.dataset[FLAGNAME] = 'found';
  121. core.listenNavigation();
  122. core.listenVideo(video);
  123. };
  124. /* if a video already exists */
  125. let video = site.get.video();
  126. if(video) found(video);
  127. /* unavoidably observate body for immediate catch */
  128. observe(document.documentElement, function(records){
  129. let video = site.get.video();
  130. if(video) found(video);
  131. }, {childList: true, subtree: true});
  132. },
  133. listenNavigation: function(){
  134. /* listen navigation (observe URL changes) */
  135. if(flags.listeningNavigation !== undefined) return;
  136. flags.listeningNavigation = true;
  137. let listener = function(e){
  138. //log(e.type, location.href);
  139. delete flags.upnextId;/* reset the upnext video id */
  140. delete flags.playedAd;/* reset the played ad status */
  141. delete flags.playedOnce;/* reset the played once status */
  142. view = core.getView(site.views);
  143. if(view && view.key === 'watch'){
  144. flags.upnextId = view.get.upnextId();
  145. if(site.is.list()) core.setPlaylistAutoplay();
  146. else core.getAutoplayLabel();
  147. }
  148. };
  149. document.addEventListener('yt-navigate-start', listener);/* click a link */
  150. window.addEventListener('popstate', listener);/* browser back or foward */
  151. listener({type: 'theVeryFirst'});/* at the very first */
  152. },
  153. listenVideo: function(video){
  154. let shouldStop = function(video){
  155. if(site.is.live()) return log('this is a live and should not stop playing');
  156. if(site.is.ad()) return log('this is an ad and should not stop playing.');
  157. if(site.is.list() && flags.autoplayOnPlaylist) return log('this is on the playlist and should not stop playing.');
  158. if(site.is.autoplay() && flags.upnextId === view.get.videoId()) return log('site is set to autoplay and should not stop playing.');
  159. if(flags.playedOnce) return log('the ad has just closed and the video should continue playing.');
  160. return true;
  161. };
  162. /* for the very immediate time */
  163. //log(video.currentSrc, 'paused:' + video.paused, 'currentTime:' + video.currentTime);
  164. if(shouldStop()){
  165. core.stopAutoplay(video);
  166. core.stopImmediateAutoplay(video);
  167. }
  168. /* the video element just changes its src attribute on any case */
  169. video.addEventListener('loadstart', function(e){
  170. //log(e.type, video.currentSrc, 'paused:' + video.paused, 'currentTime:' + video.currentTime, flags.playedAd ? 'playedAd' : '', flags.playedOnce ? 'playedOnce' : '');
  171. if(shouldStop()){
  172. core.stopAutoplay(video);
  173. /* ads just finished and the video is starting */
  174. if(!site.is.ad() && flags.playedAd && !flags.playedOnce) video.addEventListener('canplay', function(e){
  175. //log(e.type);
  176. core.imitateUnstarted(video);
  177. }, {once: true});
  178. }
  179. });
  180. /* memorize played status for restarting playing or not on after ads */
  181. video.addEventListener('playing', function(e){
  182. //log(e.type, 'currentTime:' + video.currentTime);
  183. if(site.is.ad()) return flags.playedAd = true;/* played ad on the current location */
  184. if(!flags.playedOnce) return flags.playedOnce = true;/* played once on the current location */
  185. });
  186. },
  187. stopAutoplay: function(video){
  188. //log();
  189. video.autoplay = false;
  190. video.pause();
  191. },
  192. stopImmediateAutoplay: function(video){
  193. let count = 0, isImmediate = site.is.immediate(video), startTime = site.get.startTime();
  194. //log('isImmediate:' + isImmediate, 'startTime:' + startTime, 'currentTime:' + video.currentTime);
  195. if(isImmediate) count++;/* for the very first view of the YouTube which plays a video automatically for immediate user experience */
  196. if(startTime) count++;/* for starting again from middle after seeking with query like t=123 */
  197. if(count){
  198. video.originalPlay = video.play;
  199. video.play = function(){
  200. //log('(play)', 'count:' + count, site.is.ad() ? 'ad' : '', 'currentTime:' + video.currentTime);
  201. if(site.is.ad()) return video.originalPlay();
  202. if(--count === 0) video.play = video.originalPlay;
  203. let spinner = site.get.spinner();
  204. if(spinner) spinner.style.display = 'none';
  205. };
  206. }
  207. /* I don't know why but on t < 5, it'll surely be paused but player UI is remained playing. So... */
  208. if(startTime && startTime < 5) video.addEventListener('seeked', function(e){
  209. //log(e.type, 'currentTime:' + video.currentTime);
  210. if(flags.playedAd) return;/*will imitate by canplay event listener*/
  211. core.imitateUnstarted(video);
  212. }, {once: true});
  213. },
  214. imitateUnstarted: function(video){
  215. //log();
  216. let player = site.get.moviePlayer();
  217. core.setThumbnail(video);
  218. player.classList.add('imitated-unstarted-mode');
  219. video.addEventListener('play', function(e){
  220. //log(e.type, 'now imitated-unstarted-mode', player.classList.contains('imitated-unstarted-mode'));
  221. video.addEventListener('play', function(e){
  222. //log(e.type, 'removing imitated-unstarted-mode', player.classList.contains('imitated-unstarted-mode'));
  223. player.classList.remove('imitated-unstarted-mode');
  224. }, {once: true});
  225. }, {once: true});
  226. video.play();
  227. video.pause();
  228. },
  229. setThumbnail: function(video){
  230. //log();
  231. /* normally it will automatically be set, but it won't after ads */
  232. if(view === undefined) return;
  233. core.getTarget(view.get.thumbnailOverlayImage).then(thumbnail => {
  234. thumbnail.style.backgroundImage = `url(${view.get.thumbnailURL()})`;
  235. });
  236. },
  237. setPlaylistAutoplay: function(){
  238. //log();
  239. if(flags.autoplayOnPlaylist !== undefined) return;
  240. flags.autoplayOnPlaylist = Storage.read('autoplayOnPlaylist');
  241. core.getTarget(view.get.playlistAutoplayInsertBefore).then(insertBefore => {
  242. let autoplaySwitch = createElement(html.autoplaySwitch(flags.autoplayLabel || Storage.read('autoplayLabel'))), button = autoplaySwitch.querySelector('paper-toggle-button');
  243. if(flags.autoplayOnPlaylist) button.checked = true;
  244. /* YouTube listens tap event for toggling playlist collapse */
  245. autoplaySwitch.addEventListener('tap', function(e){
  246. //log(e, button, button.checked ? 'checked' : '');
  247. if(button.checked) flags.autoplayOnPlaylist = true;
  248. else flags.autoplayOnPlaylist = false;
  249. Storage.save('autoplayOnPlaylist', flags.autoplayOnPlaylist);
  250. e.stopPropagation();
  251. });
  252. insertBefore.parentNode.insertBefore(autoplaySwitch, insertBefore);
  253. });
  254. },
  255. getAutoplayLabel: function(){
  256. //log();
  257. /* get the label everytime for catching language change, it's not such a heavy task' */
  258. core.getTarget(view.get.autoplayLabel).then(autoplayLabel => {
  259. if(autoplayLabel.textContent === flags.autoplayLabel) return;
  260. flags.autoplayLabel = autoplayLabel.textContent;
  261. Storage.save('autoplayLabel', flags.autoplayLabel);
  262. });
  263. },
  264. getView: function(views){
  265. Object.keys(views).forEach(key => views[key].key = key);
  266. let key = Object.keys(views).find(key => views[key].url.test(location.href));
  267. if(key === undefined) return log('Doesn\'t match any views:', location.href);
  268. else return views[key];
  269. },
  270. getTarget: function(selector, retry = 10, interval = 1*SECOND){
  271. const key = selector.name;
  272. const get = function(resolve, reject){
  273. let selected = selector();
  274. if(selected && selected.length > 0) selected.forEach((s) => s.dataset.selector = key);/* elements */
  275. else if(selected instanceof HTMLElement) selected.dataset.selector = key;/* element */
  276. else if(--retry) return log(`Not found: ${key}, retrying... (${retry})`), setTimeout(get, interval, resolve, reject);
  277. else return reject(new Error(`Not found: ${selector.name}, I give up.`));
  278. elements[key] = selected;
  279. resolve(selected);
  280. };
  281. return new Promise(function(resolve, reject){
  282. get(resolve, reject);
  283. });
  284. },
  285. getTargets: function(selectors, retry = 10, interval = 1*SECOND){
  286. return Promise.all(Object.values(selectors).map(selector => core.getTarget(selector, retry, interval)));
  287. },
  288. addStyle: function(name = 'style'){
  289. if(html[name] === undefined) return;
  290. let style = createElement(html[name]());
  291. document.head.appendChild(style);
  292. if(elements[name] && elements[name].isConnected) document.head.removeChild(elements[name]);
  293. elements[name] = style;
  294. },
  295. };
  296. const html = {
  297. /* YouTube itself will append the button structure to paper-toggle-button, it's so fragile!! */
  298. autoplaySwitch: (label = 'AUTOPLAY') => `
  299. <div id="head" class="style-scope ytd-compact-autoplay-renderer" data-${FLAGNAME}="playlist-autoplay">
  300. <div id="autoplay" class="style-scope ytd-compact-autoplay-renderer">${label}</div>
  301. <paper-toggle-button id="toggle" noink="" class="style-scope ytd-compact-autoplay-renderer" role="button" aria-pressed="false" tabindex="0" toggles="" aria-disabled="false" aria-label="${label}" style="touch-action: pan-y;"></paper-toggle-button>
  302. </div>
  303. `,
  304. style: () => `
  305. <style type="text/css" id="${SCRIPTID}-style">
  306. /* less bold gradient */
  307. #movie_player .ytp-gradient-bottom{
  308. background: linear-gradient(to top,
  309. rgba(0,0,0,.64) 0px,
  310. rgba(0,0,0,.49) 15px,
  311. rgba(0,0,0,.36) 30px,
  312. rgba(0,0,0,.25) 45px,
  313. rgba(0,0,0,.16) 60px,
  314. rgba(0,0,0,.09) 75px,
  315. rgba(0,0,0,.04) 90px,
  316. rgba(0,0,0,.01) 105px,
  317. rgba(0,0,0,.00) 120px,
  318. transparent
  319. ) !important;/*exponential curve*/
  320. }
  321. /* show thumbnails more clearly; affected only for .unstarted-mode */
  322. #movie_player.unstarted-mode:not(:hover) .ytp-gradient-bottom,
  323. #movie_player.imitated-unstarted-mode:not(:hover) .ytp-gradient-bottom{
  324. opacity: .5;
  325. }
  326. /* imitated unstarted mode */
  327. #movie_player.imitated-unstarted-mode .ytp-cued-thumbnail-overlay{
  328. display: block !important;
  329. z-index: 10;
  330. }
  331. /* AUTOPLAY button on the playlist */
  332. [data-${FLAGNAME}="playlist-autoplay"]{
  333. margin-bottom: 0 !important;
  334. }
  335. </style>
  336. `,
  337. };
  338. const setTimeout = window.setTimeout.bind(window), clearTimeout = window.clearTimeout.bind(window), setInterval = window.setInterval.bind(window), clearInterval = window.clearInterval.bind(window), requestAnimationFrame = window.requestAnimationFrame.bind(window);
  339. const alert = window.alert.bind(window), confirm = window.confirm.bind(window), prompt = window.prompt.bind(window), getComputedStyle = window.getComputedStyle.bind(window), fetch = window.fetch.bind(window);
  340. if(!('isConnected' in Node.prototype)) Object.defineProperty(Node.prototype, 'isConnected', {get: function(){return document.contains(this)}});
  341. class Storage{
  342. static key(key){
  343. return (SCRIPTID) ? (SCRIPTID + '-' + key) : key;
  344. }
  345. static save(key, value, expire = null){
  346. key = Storage.key(key);
  347. localStorage[key] = JSON.stringify({
  348. value: value,
  349. saved: Date.now(),
  350. expire: expire,
  351. });
  352. }
  353. static read(key){
  354. key = Storage.key(key);
  355. if(localStorage[key] === undefined) return undefined;
  356. let data = JSON.parse(localStorage[key]);
  357. if(data.value === undefined) return data;
  358. if(data.expire === undefined) return data;
  359. if(data.expire === null) return data.value;
  360. if(data.expire < Date.now()) return localStorage.removeItem(key);/*undefined*/
  361. return data.value;
  362. }
  363. static remove(key){
  364. key = Storage.key(key);
  365. delete localStorage.removeItem(key);
  366. }
  367. static delete(key){
  368. Storage.remove(key);
  369. }
  370. static saved(key){
  371. key = Storage.key(key);
  372. if(localStorage[key] === undefined) return undefined;
  373. let data = JSON.parse(localStorage[key]);
  374. if(data.saved) return data.saved;
  375. else return undefined;
  376. }
  377. }
  378. const $ = function(s, f){
  379. let target = document.querySelector(s);
  380. if(target === null) return null;
  381. return f ? f(target) : target;
  382. };
  383. const $$ = function(s, f){
  384. let targets = document.querySelectorAll(s);
  385. return f ? Array.from(targets).map(t => f(t)) : targets;
  386. };
  387. const createElement = function(html = '<span></span>'){
  388. let outer = document.createElement('div');
  389. outer.innerHTML = html;
  390. return outer.firstElementChild;
  391. };
  392. const observe = function(element, callback, options = {childList: true, characterData: false, subtree: false, attributes: false, attributeFilter: undefined}){
  393. let observer = new MutationObserver(callback.bind(element));
  394. observer.observe(element, options);
  395. return observer;
  396. };
  397. const log = function(){
  398. if(!DEBUG) return;
  399. let l = log.last = log.now || new Date(), n = log.now = new Date();
  400. let error = new Error(), line = log.format.getLine(error), callers = log.format.getCallers(error);
  401. //console.log(error.stack);
  402. console.log(
  403. SCRIPTID + ':',
  404. /* 00:00:00.000 */ n.toLocaleTimeString() + '.' + n.getTime().toString().slice(-3),
  405. /* +0.000s */ '+' + ((n-l)/1000).toFixed(3) + 's',
  406. /* :00 */ ':' + line,
  407. /* caller.caller */ (callers[2] ? callers[2] + '() => ' : '') +
  408. /* caller */ (callers[1] || '') + '()',
  409. ...arguments
  410. );
  411. };
  412. log.formats = [{
  413. name: 'Firefox Scratchpad',
  414. detector: /MARKER@Scratchpad/,
  415. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1],
  416. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  417. }, {
  418. name: 'Firefox Console',
  419. detector: /MARKER@debugger/,
  420. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1],
  421. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  422. }, {
  423. name: 'Firefox Greasemonkey 3',
  424. detector: /\/gm_scripts\//,
  425. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1],
  426. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  427. }, {
  428. name: 'Firefox Greasemonkey 4+',
  429. detector: /MARKER@user-script:/,
  430. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1] - 500,
  431. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  432. }, {
  433. name: 'Firefox Tampermonkey',
  434. detector: /MARKER@moz-extension:/,
  435. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1] - 2,
  436. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  437. }, {
  438. name: 'Chrome Console',
  439. detector: /at MARKER \(<anonymous>/,
  440. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)?$/)[1],
  441. getCallers: (e) => e.stack.match(/[^ ]+(?= \(<anonymous>)/gm),
  442. }, {
  443. name: 'Chrome Tampermonkey',
  444. detector: /at MARKER \(chrome-extension:.*?\/userscript.html\?name=/,
  445. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)?$/)[1] - 1,
  446. getCallers: (e) => e.stack.match(/[^ ]+(?= \(chrome-extension:)/gm),
  447. }, {
  448. name: 'Chrome Extension',
  449. detector: /at MARKER \(chrome-extension:/,
  450. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)?$/)[1],
  451. getCallers: (e) => e.stack.match(/[^ ]+(?= \(chrome-extension:)/gm),
  452. }, {
  453. name: 'Edge Console',
  454. detector: /at MARKER \(eval/,
  455. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)$/)[1],
  456. getCallers: (e) => e.stack.match(/[^ ]+(?= \(eval)/gm),
  457. }, {
  458. name: 'Edge Tampermonkey',
  459. detector: /at MARKER \(Function/,
  460. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)$/)[1] - 4,
  461. getCallers: (e) => e.stack.match(/[^ ]+(?= \(Function)/gm),
  462. }, {
  463. name: 'Safari',
  464. detector: /^MARKER$/m,
  465. getLine: (e) => 0,/*e.lineが用意されているが最終呼び出し位置のみ*/
  466. getCallers: (e) => e.stack.split('\n'),
  467. }, {
  468. name: 'Default',
  469. detector: /./,
  470. getLine: (e) => 0,
  471. getCallers: (e) => [],
  472. }];
  473. log.format = log.formats.find(function MARKER(f){
  474. if(!f.detector.test(new Error().stack)) return false;
  475. //console.log('////', f.name, 'wants', 0/*line*/, '\n' + new Error().stack);
  476. return true;
  477. });
  478. core.initialize();
  479. if(window === top && console.timeEnd) console.timeEnd(SCRIPTID);
  480. })();