Advertisement
Guest User

Untitled

a guest
Apr 18th, 2024
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Acorn cannon log helper
  3. // @match          *://donguri.5ch.net/cannonlogs
  4. // @connect        menu.5ch.net
  5. // @connect        itest.5ch.net
  6. // @grant          GM_xmlhttpRequest
  7. // @grant          GM_openInTab
  8. // @version        0.1
  9. // ==/UserScript==
  10.  
  11. let boards = new Promise((resolve, reject) => {
  12.     GM_xmlhttpRequest({
  13.         url: "https://menu.5ch.net/bbsmenu.json",
  14.         responseType: "json",
  15.         onload: (resp => {
  16.             resolve(resp.response);
  17.         }),
  18.         onerror: (resp => {
  19.             reject(resp);
  20.         }),
  21.     });
  22. }).then(json => {
  23.     let serverMap = {};
  24.     for (let cats of json.menu_list) {
  25.         for (let board of cats.category_content) {
  26.             serverMap[board.directory_name] = (new URL(board.url)).hostname;
  27.         }
  28.     }
  29.     return serverMap;
  30. }).catch(resp => console.error(resp));
  31.  
  32. function attachSearchButton(parent, board, thread, date, time)
  33. {
  34.     let button = document.createElement("a");
  35.     button.style.marginLeft = "4px";
  36.     button.style.fontSize = "small";
  37.     button.href = "javasctipt:void(0)";
  38.     button.textContent = "レスを検索";
  39.     button.addEventListener("click", evt => {
  40.         evt.target.textContent = "検索中...";
  41.         let host;
  42.         boards.then(map => {
  43.             host = map[board];
  44.             let subdomain = host?.split(".")[0];
  45.             return new Promise((resolve, reject) => {
  46.                 GM_xmlhttpRequest({
  47.                     url: `https://itest.5ch.net/public/newapi/client.php?subdomain=${subdomain}&board\=${board}\&dat\=${thread}`,
  48.                     responseType: "json",
  49.                     onload: (resp => {
  50.                         resolve(resp.response);
  51.                     }),
  52.                     onerror: (resp => {
  53.                         reject(resp);
  54.                     }),
  55.                 });
  56.             });
  57.         }).then(json => {
  58.             for (let comment of json.comments) {
  59.                 if (comment[3].endsWith(time) && comment[3].startsWith(date)) {
  60.                     let url = `https://${host}/test/read.cgi/${board}/${thread}/${comment[0]}`;
  61.                     GM_openInTab(url)
  62.                     button.textContent = "開く";
  63.                     button.href = url;
  64.                     button.target = "_blank";
  65.                     break;
  66.                 }
  67.             }
  68.         }).catch(resp => {
  69.             button.textContent = "エラー";
  70.             console.error(resp)
  71.         });
  72.     }, {once: true});
  73.     parent.appendChild(button);
  74. }
  75.  
  76. for (let td of document.querySelectorAll("tr td:nth-child(2)")) {
  77.     let content = td.textContent;
  78.     content = content.substr(content.lastIndexOf("|")+1).trim();
  79.     let time = content.match(/[\d]{2}:[\d]{2}:[\d]{2}\.[\d]{2}/);
  80.     let date = content.match(/[\d]{4}\/[\d]{2}\/[\d]{2}/);
  81.     content = content.split(" ");
  82.     attachSearchButton(td, content[0], content[1], date, time);
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement