Last active
November 17, 2018 14:37
-
-
Save toriwasa/eb3cb90808fe80dabba9e9fe0d78e07d to your computer and use it in GitHub Desktop.
Arcadiaをローカルに落として見たい人向けにリンク書き換えるユーザースクリプト書いたやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Arcadia local Viewer | |
// @namespace http://tampermonkey.net/ | |
// @version 0.41 | |
// @description Replace URL of Arcadia, to read in local file. | |
// @author toriwasa | |
// @match file:///D:/test/*.html | |
// @grant none | |
// ==/UserScript== | |
function getNodesByXpath(xpath) { | |
return document.evaluate( | |
xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
} | |
// 作品話数表示リンクを置き換える | |
var title_nodes = getNodesByXpath( | |
'//a[contains(@href, \'act=dump\')]/@href' | |
) | |
if(title_nodes.snapshotLength) { | |
for (let i = 0; i < title_nodes.snapshotLength; i++) { | |
let e = title_nodes.snapshotItem(i); | |
// リンク内のパラメータ部分を取り出す | |
let m = e.nodeValue.match(/(\?)(.*)/) | |
let p = m[m.length - 1] | |
// パラメータをパースしてカテゴリと作品IDと話数IDを取り出す | |
let urlParams = new URLSearchParams(p); | |
var cate = urlParams.get('cate') | |
let ssid = urlParams.get('all') | |
let epid = urlParams.get('n').match(/\d+/) | |
// 作品一覧と同じディレクトリ内のカテゴリ_作品ID_話数ID.htmlにリンクさせる | |
e.nodeValue = './' + cate + '_' + ssid + '_' + epid + '.html' | |
} | |
} | |
// カテゴリリンクを置き換える | |
var category_nodes = getNodesByXpath( | |
'//a[contains(@href, \'act=list\')]/@href' | |
) | |
if(category_nodes.snapshotLength) { | |
for (let i = 0; i < category_nodes.snapshotLength; i++) { | |
let e = category_nodes.snapshotItem(i); | |
// リンク内のパラメータ部分を取り出す | |
let m = e.nodeValue.match(/(\?)(.*)/) | |
let p = m[m.length - 1] | |
// パラメータをパースしてカテゴリを取り出す | |
let urlParams = new URLSearchParams(p); | |
let cate = urlParams.get('cate') | |
// 作品一覧と同じディレクトリ内のカテゴリ_1.htmlにリンクさせる | |
e.nodeValue = './' + cate + '_1.html' | |
} | |
} | |
// XXX板だけ別途対応する | |
var xxx_nodes = getNodesByXpath( | |
'//a[contains(@href, \'act=18attention\')]/@href' | |
) | |
if(xxx_nodes.snapshotLength) { | |
for (let i = 0; i < xxx_nodes.snapshotLength; i++) { | |
let e = xxx_nodes.snapshotItem(i); | |
// リンク内のパラメータ部分を取り出す | |
let m = e.nodeValue.match(/(\?)(.*)/) | |
let p = m[m.length - 1] | |
// パラメータをパースしてカテゴリを取り出す | |
let urlParams = new URLSearchParams(p); | |
let cate = urlParams.get('cate') | |
// 作品一覧と同じディレクトリ内の18_1.htmlにリンクさせる | |
e.nodeValue = './18_1.html' | |
} | |
} | |
// 次の50件のページ番号を取得する | |
var next_page_nodes = getNodesByXpath( | |
'//input[contains(@value, \'次の50件\')]/preceding-sibling::input[@name=\'page\']/@value' | |
) | |
if(next_page_nodes.snapshotLength) { | |
let e = next_page_nodes.snapshotItem(1); | |
var next_page = e.nodeValue | |
} | |
// 次の50件フォーム要素を取得して置換する | |
var next_nodes = getNodesByXpath( | |
'//input[contains(@value, \'次の50件\')]/..' | |
) | |
if(next_nodes.snapshotLength) { | |
for (let i = 0; i < next_nodes.snapshotLength; i++) { | |
let e = next_nodes.snapshotItem(i); | |
// リンクに置き換える | |
e.innerHTML = '<a href="' + cate + '_' + next_page + '.html">次の50件</a>' | |
} | |
} | |
// 前の50件のページ番号を取得する | |
var before_page_nodes = getNodesByXpath( | |
'//input[contains(@value, \'前の50件\')]/preceding-sibling::input[@name=\'page\']/@value' | |
) | |
if(before_page_nodes.snapshotLength) { | |
let e = before_page_nodes.snapshotItem(1); | |
var before_page = e.nodeValue | |
} | |
// 前の50件フォーム要素を取得して置換する | |
var before_nodes = getNodesByXpath( | |
'//input[contains(@value, \'前の50件\')]/..' | |
) | |
// 前の50件が0ページ目の場合のみ処理しない | |
if(before_page != 0) { | |
if(before_nodes.snapshotLength) { | |
for (let i = 0; i < before_nodes.snapshotLength; i++) { | |
let e = before_nodes.snapshotItem(i); | |
// リンクに置き換える | |
e.innerHTML = '<a href="' + cate + '_' + before_page + '.html">前の50件</a>' | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment