Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Acorn cannon log helper
- // @match *://donguri.5ch.net/cannonlogs
- // @connect menu.5ch.net
- // @connect itest.5ch.net
- // @grant GM_xmlhttpRequest
- // @grant GM_openInTab
- // @version 0.1
- // ==/UserScript==
- let boards = new Promise((resolve, reject) => {
- GM_xmlhttpRequest({
- url: "https://menu.5ch.net/bbsmenu.json",
- responseType: "json",
- onload: (resp => {
- resolve(resp.response);
- }),
- onerror: (resp => {
- reject(resp);
- }),
- });
- }).then(json => {
- let serverMap = {};
- for (let cats of json.menu_list) {
- for (let board of cats.category_content) {
- serverMap[board.directory_name] = (new URL(board.url)).hostname;
- }
- }
- return serverMap;
- }).catch(resp => console.error(resp));
- function attachSearchButton(parent, board, thread, date, time)
- {
- let button = document.createElement("a");
- button.style.marginLeft = "4px";
- button.style.fontSize = "small";
- button.href = "javasctipt:void(0)";
- button.textContent = "レスを検索";
- button.addEventListener("click", evt => {
- evt.target.textContent = "検索中...";
- let host;
- boards.then(map => {
- host = map[board];
- let subdomain = host?.split(".")[0];
- return new Promise((resolve, reject) => {
- GM_xmlhttpRequest({
- url: `https://itest.5ch.net/public/newapi/client.php?subdomain=${subdomain}&board\=${board}\&dat\=${thread}`,
- responseType: "json",
- onload: (resp => {
- resolve(resp.response);
- }),
- onerror: (resp => {
- reject(resp);
- }),
- });
- });
- }).then(json => {
- for (let comment of json.comments) {
- if (comment[3].endsWith(time) && comment[3].startsWith(date)) {
- let url = `https://${host}/test/read.cgi/${board}/${thread}/${comment[0]}`;
- GM_openInTab(url)
- button.textContent = "開く";
- button.href = url;
- button.target = "_blank";
- break;
- }
- }
- }).catch(resp => {
- button.textContent = "エラー";
- console.error(resp)
- });
- }, {once: true});
- parent.appendChild(button);
- }
- for (let td of document.querySelectorAll("tr td:nth-child(2)")) {
- let content = td.textContent;
- content = content.substr(content.lastIndexOf("|")+1).trim();
- let time = content.match(/[\d]{2}:[\d]{2}:[\d]{2}\.[\d]{2}/);
- let date = content.match(/[\d]{4}\/[\d]{2}\/[\d]{2}/);
- content = content.split(" ");
- attachSearchButton(td, content[0], content[1], date, time);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement