Greasy Fork

Greasy Fork is available in English.

「Show more」ボタンを自動で押す

pubmed reddit ニコレポ ニコ静画 duckduckgo pixiv youtube

当前为 2020-10-31 提交的版本,查看 最新版本

// ==UserScript==
// @name 「Show more」ボタンを自動で押す
// @description pubmed reddit ニコレポ ニコ静画 duckduckgo pixiv youtube
// @version 0.1
// @match *://www.nicovideo.jp/my/*
// @match *://www.nicovideo.jp/user/*
// @match *://seiga.nicovideo.jp/seiga/*
// @match *://duckduckgo.com/*
// @match *://www.pixiv.net/*
// @match *://www.reddit.com/*
// @match *://www.reddit.com/r/*
// @match *://www.youtube.com
// @match *://www.youtube.com/*
// @match *://www.youtube.com/watch*
// @match *://pubmed.ncbi.nlm.nih.gov/*
// @run-at document-idle
// @grant none
// @namespace http://greasyfork.icu/users/181558
// ==/UserScript==

(function() {

  const moreButtonIntervalMsDefault = 3500;

  const siteinfo = [{ //
    urlRegExp: '//pubmed.ncbi',
    moreButtonXPath: '//button[@class="load-button next-page"]',
    moreButtonSame: true,
    moreButtonIntervalMs: 500,
    /*
  }, { // reddit 常にBest順にしない版
    urlRegExp: '//www.reddit.com/r/',
    moreButtonXPath: '//font[contains(text(),"ディスカッション全体を表示")]|.//font[contains(text(),"ディスカッション全体を見る")]|.//button[contains(text(),"View entire discussion")]|.//button[contains(text(),"View Entire Discussion")]',
    moreButtonSame: false,
    moreButtonIntervalMs: 500,
    */
  }, { // reddit 常にBest順にする版
    urlRegExp: '//www.reddit.com/r/',
    moreButtonXPath: '//font[contains(text(),"ディスカッション全体を表示")]|.//font[contains(text(),"ディスカッション全体を見る")]|.//button[contains(text(),"View entire discussion")]|.//button[contains(text(),"View Entire Discussion")]|.//font[text()="ベスト"]|.//span[text()="best"]',
    moreButtonSame: false,
    moreButtonIntervalMs: 500,

    /*
       }, { // サイトがダウン?
        urlRegExp: '//www.ytplaylist.com',
        moreButtonXPath: '//li[@id="search-more-results"]/a',
        moreButtonIntervalMs: 500,
        focusID: 'player'
      }, { // サイトがダウン?
        urlRegExp: '//musictonic.com/music/',
        moreButtonXPath: '',
        focusID: 'player_container',
        optionFunc: 'musictonic'
    */
  }, { //
    urlRegExp: '//www.nicovideo.jp/my/top|//www.nicovideo.jp/user/|//www.nicovideo.jp/my/',
    moreButtonXPath: '//div[@class="next-page"]/a|//a[@class="next-page-link timeline-next-link"]|//button[@class="NicorepoTimeline-more"]',
    moreButtonIntervalMs: 1500,
    moreButtonSame: true,
    focusID: ''
  }, { //
    urlRegExp: '//seiga.nicovideo.jp/seiga/',
    moreButtonXPath: '//a[@id="gif_play_button" and contains(text()," gifアニメを再生")]/span',
    moreButtonIntervalMs: 500,
    focusID: '',
    focusIntervalMs: ''
    /*  }, { // 新UIでは不要
        urlRegExp: '//twitter.com/',
        moreButtonXPath: '//span[text()="表示"]|//div[@class="Tombstone"]/button|//button[@class="new-tweets-bar js-new-tweets-bar"]|//button[@class="Tombstone-action js-display-this-media btn-link"]',
        moreButtonIntervalMs: '',
        focusID: '',
        focusIntervalMs: ''
    */
  }, { //
    urlRegExp: '//duckduckgo.com/',
    moreButtonXPath: '//a[@class="result--more__btn btn btn--full"]',
    moreButtonIntervalMs: '',
    focusID: '',
    focusIntervalMs: ''
  }, { //
    urlRegExp: '//www.pixiv.net/',
    moreButtonXPath: '//div[text()="すべて見る"]/..',
    moreButtonIntervalMs: '',
    focusID: '',
    focusIntervalMs: ''
  }, { //
    urlRegExp: '',
    moreButtonXPath: '',
    moreButtonIntervalMs: '',
    focusID: '',
    focusIntervalMs: ''
  }, { //
    urlRegExp: '',
    moreButtonXPath: '',
    moreButtonIntervalMs: '',
    focusID: '',
    focusIntervalMs: ''
  }, { //
    urlRegExp: '//www.youtube.com',
    //    moreButtonXPath: '//span[contains(text(),"続きを読む")]|//yt-formatted-string[contains(text(),"返信を表示")]|//span[contains(text()," さんの返信を表示")]|//span[contains(text()," 件を表示")]|//yt-formatted-string[text()="もっと見る"]|//paper-button[last()]/span[contains(text(),\"続きを読む\")]|//span/font[contains(text(),"続きを読む")]|//font[contains(text(),"返信を表示")]|//span/font[contains(text()," さんの返信を表示")]|//span/font[contains(text()," 件を表示")]|//span/font/font[contains(text(),"続きを読む")]|//yt-formatted-string/font[text()="もっと見る"]|//paper-button[@id="button" and @elevation="0" and @aria-label="検索フィルタ" and @aria-pressed="false"]/yt-icon',
    moreButtonXPath: '//paper-button[@id="button" and @elevation="0" and @aria-label="検索フィルタ" and @aria-pressed="false"]/yt-icon',
    moreButtonIntervalMs: 1000,
    focusID: '',
    focusIntervalMs: '',
  }];

  var thissite = 0;
  for (var i = 0; i < siteinfo.length; i++) {
    if (siteinfo[i].urlRegExp == "") continue;
    if (location.href.match(siteinfo[i].urlRegExp)) {
      thissite = i;
    }
  }
  //  console.log(thissite)
  if (siteinfo[thissite].moreButtonXPath) {
    //console.log("見つかりました");
    setInterval(kurikku, siteinfo[thissite].moreButtonIntervalMs ? siteinfo[thissite].moreButtonIntervalMs : moreButtonIntervalMsDefault);
  }

  if (siteinfo[thissite].focusID) setInterval(focusid, siteinfo[thissite].focusIntervalMs ? siteinfo[thissite].focusIntervalMs : moreButtonIntervalMsDefault);

  //  console.log(siteinfo[thissite])

  /*
  if (location.href.match("musictonic")) {
    eleget0('//input[@id="q" and @name="q"]').value = eleget0('//h1[@class="artist"]').innerText.replace(/ Music Videos/, "") + " ";
    GM_addStyle("ul.videos li a { text-decoration: none; color: #999; }");
  }
  */

  return;

  function kurikku() { //console.log("押します")
    for (let ele of elegeta(siteinfo[thissite].moreButtonXPath)) {
      //    console.log(isinscreen(ele) +" , "+ele.dataset.dataClickedAlready)
      if (isinscreen(ele) && ele.dataClickedAlready != true) { // 一度押した要素には.dataClickedAlreadyプロパティがついている
        ele.click();
        if (siteinfo[thissite].moreButtonSame) {} else {
          ele.dataClickedAlready = true; // 一度押したら.dataClickedAlreadyプロパティをtrueにする
          //        console.log(ele.outerHTML);
          break;
        }
        break; // 1度に一個しか押さない
      }
    }
    return;
  }

  function focusid() {
    if (document.activeElement != document.body && document.activeElement != null && /input|textarea/i.test(document.activeElement.tagName)) return; //入力フォームなら戻る
    if (window.getSelection() != "") return; //選択文字列があるなら戻る
    if (/BODY|A/i.test(document.activeElement.tagName)) {
      var ele = document.getElementById(siteinfo[thissite].focusID);
      if (ele) {
        ele.tabIndex = 0;
        ele.focus();
      }
    }
    return;
  }

  function isinscreen(ele) {
    if (!ele) return;
    var eler = ele.getBoundingClientRect();
    return (eler.top > 0 && eler.left > 0 && eler.left < document.documentElement.clientWidth && eler.top < Math.min(window.innerHeight, document.documentElement.clientHeight));
  }

  function eleget0(xpath) {
    var ele = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    return ele.snapshotLength > 0 ? ele.snapshotItem(0) : "";
  }

  function elegeta(xpath, node = document) {
    var ele = document.evaluate("." + xpath, node, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    var array = [];
    for (var i = 0; i < ele.snapshotLength; i++) array[i] = ele.snapshotItem(i);
    return array;
  }

})()