// ==UserScript==
// @name 「Show more」ボタンを自動で押す
// @description PubMed reddit ニコレポ ニコニコ静画 DuckDuckGo Pixiv Youtube Quora 音泉 Yahoo!ニュース ライブドアニュース Togetter gooニュース はてな匿名ダイアリー Yahoo!知恵袋
// @version 0.1.5
// @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/*
// @match https://www.quora.com/*
// @match https://www.onsen.ag/
// @match *://news.yahoo.co.jp/pickup*
// @match https://news.livedoor.com/topics/detail/*
// @match https://togetter.com/*
// @match *://news.goo.ne.jp/*
// @match *://anond.hatelabo.jp/*
// @match *://detail.chiebukuro.yahoo.co.jp/qa/question_detail/*
// @run-at document-idle
// @grant GM_addStyle
// @namespace https://gf.qytechs.cn/users/181558
// ==/UserScript==
(function() {
var clickedalready = [];
var rest = 0;
const moreButtonIntervalDefault = 1500;
const siteinfo = [{
url: '//detail.chiebukuro.yahoo.co.jp/qa/question_detail/',
moreButton: '//div[text()="その他の回答をもっと見る"]|//button[text()="…続きを読む"]|//div/button[@data-ylk="rsec:ans_re;slk:more"]/div',
moreButtonInterval: 500,
}, {
url: '//anond.hatelabo.jp/',
moreButton: '//img[@class="icon" and @src="/images/common/open.gif"]/..',
moreButtonInterval: 400,
//GM_addStyle("div.section p{line-height:1}")
}, {
url: '//news.goo.ne.jp/',
moreButton: '//a[@id="topics_1_more"]',
}, {
url: '//togetter.com/',
moreButton: '//div/a[@id="more_tweet_btn"]',
}, {
url: '//news.livedoor.com/topics/detail/',
moreButton: '//a[(text()="記事を読む")]',
}, { //
url: '//news.yahoo.co.jp/pickup',
moreButton: '//div/p/a[text()="続きを読む"]',
}, { //
url: '//www.onsen.ag',
moreButton: '//a[@class="load-more-btn"]',
moreButtonSame: true,
moreButtonInterval: 1000,
}, { //
url: '//pubmed.ncbi',
moreButton: '//button[@class="load-button next-page"]',
moreButtonSame: true,
moreButtonInterval: 1000,
/*
}, { // reddit 常にBest順にしない版
url: '//www.reddit.com/r/',
moreButton: '//font[contains(text(),"ディスカッション全体を表示")]|.//font[contains(text(),"ディスカッション全体を見る")]|.//button[contains(text(),"View entire discussion")]|.//button[contains(text(),"View Entire Discussion")]',
moreButtonSame: false,
moreButtonInterval: 500,
*/
}, { // reddit 常にBest順にする版
url: '//www.reddit.com/r/',
moreButton: '//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,
moreButtonInterval: 500,
/*
}, { // サイトがダウン?
url: '//www.ytplaylist.com',
moreButton: '//li[@id="search-more-results"]/a',
moreButtonInterval: 500,
focusID: 'player'
}, { // サイトがダウン?
url: '//musictonic.com/music/',
moreButton: '',
focusID: 'player_container',
optionFunc: 'musictonic'
*/
}, { //
url: '//www.nicovideo.jp/my/top|//www.nicovideo.jp/user/|//www.nicovideo.jp/my',
moreButton: '//div[@class="next-page"]/a|//a[@class="next-page-link timeline-next-link"]|//button[@class="NicorepoTimeline-more"]|//button[@class="ShowMoreList-more"]',
moreButtonInterval: 1500,
moreButtonSame: true,
}, { //
url: '//seiga.nicovideo.jp/seiga/',
moreButton: '//a[@id="gif_play_button" and contains(text()," gifアニメを再生")]/span',
moreButtonInterval: 500,
}, { //
url: '//duckduckgo.com/',
moreButton: '//a[@class="result--more__btn btn btn--full"]',
moreButtonInterval: 500,
}, { //
url: '//www.pixiv.net/',
moreButton: '//div[text()="すべて見る"]/..',
moreButtonInterval: 2000,
}, { //
url: '//www.quora.com/',
moreButton: '//div[text()="Continue Reading"]|//font[text()="読み続けてください"]',
moreButtonInterval: 200,
}, { //
url: '',
moreButton: '',
moreButtonInterval: '',
focusID: '',
focusInterval: ''
}, { //
url: '//www.youtube.com',
requireUrl: /\/\/www\.youtube\.com\/watch\?|\/\/www\.youtube\.com\/results\?/,
moreButton: '//tp-yt-paper-button[@id="button" and @role="button" and @animated="" and @aria-label="検索フィルタ" and @aria-pressed="false"]/yt-formatted-string|//yt-formatted-string[@slot="more-button"]|//ytd-button-renderer[@id="more-replies"]|//paper-button[@id="button" and contains(aria-label,"を表示")]|//yt-formatted-string[@class="style-scope yt-next-continuation" and contains(text(),"を表示")]|//yt-formatted-string[@class="style-scope ytd-button-renderer" and contains(text(),"を表示")]|//span[@class="more-button style-scope ytd-comment-renderer" and text()="続きを読む"]|//yt-formatted-string[contains(@class,"style-scope ytd-button-renderer") and contains(text(),"を表示")]|//yt-formatted-string[@class="style-scope ytd-button-renderer"]/span[contains(text(),"を表示")]', // コメントも全展開(簡易、不完全)版
// moreButton: '//tp-yt-paper-button[@id="button" and @role="button" and @animated="" and @aria-label="検索フィルタ" and @aria-pressed="false"]/yt-formatted-string', // フィルタ展開のみ版
moreButtonInterval: 600,
funcUrlChanged: () => {
rest = 1;
clickedalready = [];
setTimeout(() => { rest = 0; }, 3000);
},
}, { //
url: '', // 対応させるページのURLの正規表現 matchすると有効
moreButton: '', // クリックさせる要素のXPath
moreButtonSame: false, // trueなら同じボタンを何度でも押す falseなら1回のみ
moreButtonInterval: '', // クリックする間隔(ms) 省略時はデフォルト(1500)
focusID: 0, // trueならmoreButtonをfocusIntervalごとにfocusする
focusInterval: '', // (focusIDが1のときのみ)moreButtonをfocusする間隔(ms)
funcUrlChanged: null, // urlが変化した時に実行する関数 SPAで使う
requireUrl: '', // urlにmatchしないと動作を飛ばす正規表現 youtubeのようなSPAで特定url以外では確実に動作を止めたいサイトでintervalごとに常時チェックしている
}];
var thissite = 0;
for (var i = 0; i < siteinfo.length; i++) {
if (siteinfo[i].url == "") continue;
if (location.href.match(siteinfo[i].url)) {
thissite = i;
}
}
var SITE = { ...siteinfo[thissite] };
if (SITE.funcUrlChanged) { // URL変化時に実行する関数があれば登録
var observeUrlHasChangedhref = location.href;
var observeUrlHasChanged = new MutationObserver(mutations => {
if (observeUrlHasChangedhref !== location.href) {
observeUrlHasChangedhref = location.href;
SITE.funcUrlChanged();
// console.log("url has changed")
}
});
observeUrlHasChanged.observe(document, { childList: true, subtree: true });
}
if (SITE.moreButton) setTimeout(() => { setInterval(kurikku, SITE.moreButtonInterval ? SITE.moreButtonInterval : moreButtonIntervalDefault); }, SITE.delay ? SITE.delay : 1);
if (SITE.focusID) setInterval(focusid, SITE.focusInterval ? SITE.focusInterval : moreButtonIntervalDefault);
/*
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() {
if (rest || !(location.href.match(SITE.requireUrl))) return;
for (let ele of elegeta(SITE.moreButton)) {
if (!(clickedalready.some(e => e === ele)) && isinscreen(ele)) {
ele.click();
if (SITE.moreButtonSame) {} else {
clickedalready.push(ele); // 一度押した
break;
}
break; // 1度に一個しか押さない
}
}
}
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(SITE.focusID);
if (ele) {
ele.tabIndex = 0;
ele.focus();
}
}
}
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;
}
})();