// ==UserScript== // @name 国学大师页码链接工具 Guoxuedashi Page Linker // @namespace http://tampermonkey.net/ // @version 1.0.1 // @description 为国学大师网查询到的页码添加超链接以打开本地PDF文件对应页码 Generate page links for Guoxuedashi website based on page number in the table cell element // @author 微笑如此美妙 // @match *www.guoxuedashi.net/* // @match *dict.variants.moe.edu.tw/variants/rbt/query_by_standard_tiles.rbt?command=clear // @match *humanum.arts.cuhk.edu.hk/Lexis/lexi-can/* // @grant none // @downloadURL none // ==/UserScript== // 本脚本需配合浏览器扩展方可点开本地文件链接,扩展下载链接:https://chrome.google.com/webstore/detail/enable-local-file-links/nikfmfgobenbhmocjaaboihbeocackld // 扩展名称:Enable local file links;版本:v0.8.0;备用下载链接:https://crxdl.com/;文件大小为6.07k,下载完成后将crx文件拖动到浏览器管理扩展页(edge://extensions/)即可安装;确保管理扩展页的开发者模式打开,否则无法安装 // 汉语大字典目前可以直接访问,其他工具书PDF请重命名为拼音直接放置D盘即可调用,如字源为ziyuan.pdf、汉语大词典第1卷为hanyudacidian1.pdf,以此类推 if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { // 国语辞典、异体字典与粤语字库等链接的放置及关键词复制 (function () { "use strict"; const res = document.getElementsByClassName("tit03")[0]; var keyword = res.innerText.substring(3); let link1 = `https://dict.revised.moe.edu.tw/search.jsp?md=1&word=${keyword}`; let link2 = `https://dict.variants.moe.edu.tw/variants/rbt/query_by_standard_tiles.rbt?command=clear`; let link3 = `https://humanum.arts.cuhk.edu.hk/Lexis/lexi-can/`; let link4 = `http://www.czyzd.com/search?keyword=${keyword}`; let link5 = `https://www.syndict.com/w2p.php?word=${keyword}&item=hak`; let link6 = `https://www.zdic.net/hans/${keyword}`; // res.innerHTML += `   📙国语辞典📕异体字典📒粤语字库📘潮州字典📓客典📚汉典`; res.innerHTML += `  ➟ 国语辞典异体字典粤语字库潮州字典客典汉典`; document .querySelector( "body > div:nth-child(3) > div.info.l > div.info_content.zj.clearfix > div.info_txt2.clearfix > h2:nth-child(1)" ) .addEventListener("click", function () { // 复制关键词 let textArea = document.createElement("textarea"); textArea.value = keyword; document.body.appendChild(textArea); textArea.select(); document.execCommand("copy"); console.log(document.execCommand("copy")); document.body.removeChild(textArea); }); })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《汉语大字典》 (function() { 'use strict'; const tds = document.querySelectorAll("td"); for (const td of tds) { let content = td.innerText.trim(); if (content === '汉语大字典') { let pageNumber = parseInt(td.nextElementSibling.textContent.match(/\d+/)[0]) + 0; let link = `https://homeinmists.ilotus.org/hd/hydzd3.php?st=term&kw=${pageNumber}`; td.nextElementSibling.innerHTML = `${td.nextElementSibling.innerHTML}`; } } })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《中华字海》 (function() { 'use strict'; const tds = document.querySelectorAll("td"); for (const td of tds) { let content = td.innerText.trim(); if (content === '中华字海') { let pageNumber = parseInt(td.nextElementSibling.textContent.match(/\d+/)[0]) + 84; let link = `file:///D:/zhonghuazihai.pdf#page=${pageNumber}`; td.nextElementSibling.innerHTML = `${td.nextElementSibling.innerHTML}`; } } })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《字源》兼容双链接 (function() { 'use strict'; const tds = document.querySelectorAll("td"); for (const td of tds) { let content = td.innerText.trim(); if (content === '字 源') { let matchedNumbers = td.nextElementSibling.textContent.match(/\d+/g); if (matchedNumbers && matchedNumbers.length >= 1) { for (let i = 0; i < matchedNumbers.length; i++) { let pageNumber = parseInt(matchedNumbers[i]); if (pageNumber <= 467) { pageNumber += 12; } else if (pageNumber <= 870) { pageNumber += 13; } else if (pageNumber >= 870) { pageNumber += 15; } matchedNumbers[i] = pageNumber; } let originTextArray = td.nextElementSibling.innerHTML.split(/[\u3000\s]+/); // 按全角空格分隔源文本 let link0 = `file:///D:/ziyuan.pdf#page=${matchedNumbers[0]}`; let link1 = `file:///D:/ziyuan.pdf#page=${matchedNumbers[1]}`; td.nextElementSibling.innerHTML = `${originTextArray[0]} ${originTextArray[1]}`; } } } })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《王力古汉语字典》异步加载故每隔1秒(1000毫秒)自动执行直至加载完成并完成修改 (function() { 'use strict'; let hasModified = false; // 添加一个标记,标记是否已经执行过修改操作 const intervalId = setInterval(function() { const tds = document.querySelectorAll("td"); for (const td of tds) { let content = td.innerText.trim(); if (content === '王力古汉语字典' && !hasModified) { // 添加判断语句判断是否已经修改过 let pageNumber = parseInt(td.nextElementSibling.textContent.match(/\d+/)[0]) + 113; let link = `file:///D:/wangliguhanyuzidian.pdf#page=${pageNumber}`; td.nextElementSibling.innerHTML = `${td.nextElementSibling.innerHTML}`; hasModified = true; // 修改标记为已执行过修改操作 clearInterval(intervalId); // 停止定时器 } } }, 1000); })(); } //《汉语大词典》共12卷如下 if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《汉语大词典》第1卷 (function() { 'use strict'; // Find all table rows const tableRows = document.querySelectorAll('table tr'); // Loop through all table rows tableRows.forEach(row => { // Find the first table cell of the row const firstCell = row.querySelector('td:first-child'); // Check if the first cell contains "汉语大词典" if (firstCell && firstCell.innerText.trim() === '汉语大词典') { // Find the third table cell of the row const thirdCell = row.querySelector('td:nth-child(3)'); // Check if the third cell contains "第1卷" if (thirdCell && thirdCell.innerText.trim().includes('第1卷')) { // Find the second table cell of the row const secondCell = row.querySelector('td:nth-child(2)'); // Check if the second cell contains "第" and "页" if (secondCell && secondCell.innerText.trim().includes('第') && secondCell.innerText.trim().includes('页')) { // Extract the page number from the second cell(最后的 + 29 表示对提取出来的页码加以调整以适应实际文件) const pageNumber = parseInt(secondCell.innerText.match(/\d+/)[0]) + 29; // Generate the page link const pageLink = `file:///D:/hanyudacidian1.pdf#page=${pageNumber}`; // Create the link element and add it to the second cell const link = document.createElement('a'); link.href = pageLink; link.target = '_blank'; link.innerHTML = secondCell.innerText.trim(); secondCell.innerHTML = ''; secondCell.appendChild(link); } } } }); })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《汉语大词典》第2卷 (function() { 'use strict'; // Find all table rows const tableRows = document.querySelectorAll('table tr'); // Loop through all table rows tableRows.forEach(row => { // Find the first table cell of the row const firstCell = row.querySelector('td:first-child'); // Check if the first cell contains "汉语大词典" if (firstCell && firstCell.innerText.trim() === '汉语大词典') { // Find the third table cell of the row const thirdCell = row.querySelector('td:nth-child(3)'); // Check if the third cell contains "第2卷" if (thirdCell && thirdCell.innerText.trim().includes('第2卷')) { // Find the second table cell of the row const secondCell = row.querySelector('td:nth-child(2)'); // Check if the second cell contains "第" and "页" if (secondCell && secondCell.innerText.trim().includes('第') && secondCell.innerText.trim().includes('页')) { // Extract the page number from the second cell(- 1744 表示减去前卷页码,+ 29 表示对页码加以调整以适应实际文件) const pageNumber = parseInt(secondCell.innerText.match(/\d+/)[0]) - 1744 + 29; // Generate the page link const pageLink = `file:///D:/hanyudacidian2.pdf#page=${pageNumber}`; // Create the link element and add it to the second cell const link = document.createElement('a'); link.href = pageLink; link.target = '_blank'; link.innerHTML = secondCell.innerText.trim(); secondCell.innerHTML = ''; secondCell.appendChild(link); } } } }); })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《汉语大词典》第3卷 (function() { 'use strict'; // Find all table rows const tableRows = document.querySelectorAll('table tr'); // Loop through all table rows tableRows.forEach(row => { // Find the first table cell of the row const firstCell = row.querySelector('td:first-child'); // Check if the first cell contains "汉语大词典" if (firstCell && firstCell.innerText.trim() === '汉语大词典') { // Find the third table cell of the row const thirdCell = row.querySelector('td:nth-child(3)'); // Check if the third cell contains "第3卷" if (thirdCell && thirdCell.innerText.trim().includes('第3卷')) { // Find the second table cell of the row const secondCell = row.querySelector('td:nth-child(2)'); // Check if the second cell contains "第" and "页" if (secondCell && secondCell.innerText.trim().includes('第') && secondCell.innerText.trim().includes('页')) { // Extract the page number from the second cell(- 3406 表示减去前卷页码,+ 29 表示对页码加以调整以适应实际文件) const pageNumber = parseInt(secondCell.innerText.match(/\d+/)[0]) - 3406 + 29; // Generate the page link const pageLink = `file:///D:/hanyudacidian3.pdf#page=${pageNumber}`; // Create the link element and add it to the second cell const link = document.createElement('a'); link.href = pageLink; link.target = '_blank'; link.innerHTML = secondCell.innerText.trim(); secondCell.innerHTML = ''; secondCell.appendChild(link); } } } }); })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《汉语大词典》第4卷 (function() { 'use strict'; // Find all table rows const tableRows = document.querySelectorAll('table tr'); // Loop through all table rows tableRows.forEach(row => { // Find the first table cell of the row const firstCell = row.querySelector('td:first-child'); // Check if the first cell contains "汉语大词典" if (firstCell && firstCell.innerText.trim() === '汉语大词典') { // Find the third table cell of the row const thirdCell = row.querySelector('td:nth-child(3)'); // Check if the third cell contains "第4卷" if (thirdCell && thirdCell.innerText.trim().includes('第4卷')) { // Find the second table cell of the row const secondCell = row.querySelector('td:nth-child(2)'); // Check if the second cell contains "第" and "页" if (secondCell && secondCell.innerText.trim().includes('第') && secondCell.innerText.trim().includes('页')) { // Extract the page number from the second cell(- 5068 表示减去前卷页码,+ 29 表示对页码加以调整以适应实际文件) const pageNumber = parseInt(secondCell.innerText.match(/\d+/)[0]) - 5068 + 29; // Generate the page link const pageLink = `file:///D:/hanyudacidian4.pdf#page=${pageNumber}`; // Create the link element and add it to the second cell const link = document.createElement('a'); link.href = pageLink; link.target = '_blank'; link.innerHTML = secondCell.innerText.trim(); secondCell.innerHTML = ''; secondCell.appendChild(link); } } } }); })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《汉语大词典》第5卷 (function() { 'use strict'; // Find all table rows const tableRows = document.querySelectorAll('table tr'); // Loop through all table rows tableRows.forEach(row => { // Find the first table cell of the row const firstCell = row.querySelector('td:first-child'); // Check if the first cell contains "汉语大词典" if (firstCell && firstCell.innerText.trim() === '汉语大词典') { // Find the third table cell of the row const thirdCell = row.querySelector('td:nth-child(3)'); // Check if the third cell contains "第5卷" if (thirdCell && thirdCell.innerText.trim().includes('第5卷')) { // Find the second table cell of the row const secondCell = row.querySelector('td:nth-child(2)'); // Check if the second cell contains "第" and "页" if (secondCell && secondCell.innerText.trim().includes('第') && secondCell.innerText.trim().includes('页')) { // Extract the page number from the second cell(- 6455 表示减去前卷页码,+ 29 表示对页码加以调整以适应实际文件) const pageNumber = parseInt(secondCell.innerText.match(/\d+/)[0]) - 6455 + 29; // Generate the page link const pageLink = `file:///D:/hanyudacidian5.pdf#page=${pageNumber}`; // Create the link element and add it to the second cell const link = document.createElement('a'); link.href = pageLink; link.target = '_blank'; link.innerHTML = secondCell.innerText.trim(); secondCell.innerHTML = ''; secondCell.appendChild(link); } } } }); })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《汉语大词典》第6卷 (function() { 'use strict'; // Find all table rows const tableRows = document.querySelectorAll('table tr'); // Loop through all table rows tableRows.forEach(row => { // Find the first table cell of the row const firstCell = row.querySelector('td:first-child'); // Check if the first cell contains "汉语大词典" if (firstCell && firstCell.innerText.trim() === '汉语大词典') { // Find the third table cell of the row const thirdCell = row.querySelector('td:nth-child(3)'); // Check if the third cell contains "第6卷" if (thirdCell && thirdCell.innerText.trim().includes('第6卷')) { // Find the second table cell of the row const secondCell = row.querySelector('td:nth-child(2)'); // Check if the second cell contains "第" and "页" if (secondCell && secondCell.innerText.trim().includes('第') && secondCell.innerText.trim().includes('页')) { // Extract the page number from the second cell(- 7983 表示减去前卷页码,+ 29 表示对页码加以调整以适应实际文件) const pageNumber = parseInt(secondCell.innerText.match(/\d+/)[0]) - 7983 + 29; // Generate the page link const pageLink = `file:///D:/hanyudacidian8.pdf#page=${pageNumber}`; // Create the link element and add it to the second cell const link = document.createElement('a'); link.href = pageLink; link.target = '_blank'; link.innerHTML = secondCell.innerText.trim(); secondCell.innerHTML = ''; secondCell.appendChild(link); } } } }); })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《汉语大词典》第7卷 (function() { 'use strict'; // Find all table rows const tableRows = document.querySelectorAll('table tr'); // Loop through all table rows tableRows.forEach(row => { // Find the first table cell of the row const firstCell = row.querySelector('td:first-child'); // Check if the first cell contains "汉语大词典" if (firstCell && firstCell.innerText.trim() === '汉语大词典') { // Find the third table cell of the row const thirdCell = row.querySelector('td:nth-child(3)'); // Check if the third cell contains "第7卷" if (thirdCell && thirdCell.innerText.trim().includes('第7卷')) { // Find the second table cell of the row const secondCell = row.querySelector('td:nth-child(2)'); // Check if the second cell contains "第" and "页" if (secondCell && secondCell.innerText.trim().includes('第') && secondCell.innerText.trim().includes('页')) { // Extract the page number from the second cell(- 9602 表示减去前卷页码,+ 29 表示对页码加以调整以适应实际文件) const pageNumber = parseInt(secondCell.innerText.match(/\d+/)[0]) - 9602 + 29; // Generate the page link const pageLink = `file:///D:/hanyudacidian7.pdf#page=${pageNumber}`; // Create the link element and add it to the second cell const link = document.createElement('a'); link.href = pageLink; link.target = '_blank'; link.innerHTML = secondCell.innerText.trim(); secondCell.innerHTML = ''; secondCell.appendChild(link); } } } }); })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《汉语大词典》第8卷 (function() { 'use strict'; // Find all table rows const tableRows = document.querySelectorAll('table tr'); // Loop through all table rows tableRows.forEach(row => { // Find the first table cell of the row const firstCell = row.querySelector('td:first-child'); // Check if the first cell contains "汉语大词典" if (firstCell && firstCell.innerText.trim() === '汉语大词典') { // Find the third table cell of the row const thirdCell = row.querySelector('td:nth-child(3)'); // Check if the third cell contains "第8卷" if (thirdCell && thirdCell.innerText.trim().includes('第8卷')) { // Find the second table cell of the row const secondCell = row.querySelector('td:nth-child(2)'); // Check if the second cell contains "第" and "页" if (secondCell && secondCell.innerText.trim().includes('第') && secondCell.innerText.trim().includes('页')) { // Extract the page number from the second cell(- 11156 表示减去前卷页码,+ 29 表示对页码加以调整以适应实际文件) const pageNumber = parseInt(secondCell.innerText.match(/\d+/)[0]) - 11156 + 29; // Generate the page link const pageLink = `file:///D:/hanyudacidian8.pdf#page=${pageNumber}`; // Create the link element and add it to the second cell const link = document.createElement('a'); link.href = pageLink; link.target = '_blank'; link.innerHTML = secondCell.innerText.trim(); secondCell.innerHTML = ''; secondCell.appendChild(link); } } } }); })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《汉语大词典》第9卷 (function() { 'use strict'; // Find all table rows const tableRows = document.querySelectorAll('table tr'); // Loop through all table rows tableRows.forEach(row => { // Find the first table cell of the row const firstCell = row.querySelector('td:first-child'); // Check if the first cell contains "汉语大词典" if (firstCell && firstCell.innerText.trim() === '汉语大词典') { // Find the third table cell of the row const thirdCell = row.querySelector('td:nth-child(3)'); // Check if the third cell contains "第9卷" if (thirdCell && thirdCell.innerText.trim().includes('第9卷')) { // Find the second table cell of the row const secondCell = row.querySelector('td:nth-child(2)'); // Check if the second cell contains "第" and "页" if (secondCell && secondCell.innerText.trim().includes('第') && secondCell.innerText.trim().includes('页')) { // Extract the page number from the second cell(- 12517 表示减去前卷页码,+ 29 表示对页码加以调整以适应实际文件) const pageNumber = parseInt(secondCell.innerText.match(/\d+/)[0]) - 12517 + 29; // Generate the page link const pageLink = `file:///D:/hanyudacidian9.pdf#page=${pageNumber}`; // Create the link element and add it to the second cell const link = document.createElement('a'); link.href = pageLink; link.target = '_blank'; link.innerHTML = secondCell.innerText.trim(); secondCell.innerHTML = ''; secondCell.appendChild(link); } } } }); })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《汉语大词典》第10卷 (function() { 'use strict'; // Find all table rows const tableRows = document.querySelectorAll('table tr'); // Loop through all table rows tableRows.forEach(row => { // Find the first table cell of the row const firstCell = row.querySelector('td:first-child'); // Check if the first cell contains "汉语大词典" if (firstCell && firstCell.innerText.trim() === '汉语大词典') { // Find the third table cell of the row const thirdCell = row.querySelector('td:nth-child(3)'); // Check if the third cell contains "第10卷" if (thirdCell && thirdCell.innerText.trim().includes('第10卷')) { // Find the second table cell of the row const secondCell = row.querySelector('td:nth-child(2)'); // Check if the second cell contains "第" and "页" if (secondCell && secondCell.innerText.trim().includes('第') && secondCell.innerText.trim().includes('页')) { // Extract the page number from the second cell(- 13967 表示减去前卷页码,+ 29 表示对页码加以调整以适应实际文件) const pageNumber = parseInt(secondCell.innerText.match(/\d+/)[0]) - 13967 + 29; // Generate the page link const pageLink = `file:///D:/hanyudacidian10.pdf#page=${pageNumber}`; // Create the link element and add it to the second cell const link = document.createElement('a'); link.href = pageLink; link.target = '_blank'; link.innerHTML = secondCell.innerText.trim(); secondCell.innerHTML = ''; secondCell.appendChild(link); } } } }); })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《汉语大词典》第11卷 (function() { 'use strict'; // Find all table rows const tableRows = document.querySelectorAll('table tr'); // Loop through all table rows tableRows.forEach(row => { // Find the first table cell of the row const firstCell = row.querySelector('td:first-child'); // Check if the first cell contains "汉语大词典" if (firstCell && firstCell.innerText.trim() === '汉语大词典') { // Find the third table cell of the row const thirdCell = row.querySelector('td:nth-child(3)'); // Check if the third cell contains "第11卷" if (thirdCell && thirdCell.innerText.trim().includes('第11卷')) { // Find the second table cell of the row const secondCell = row.querySelector('td:nth-child(2)'); // Check if the second cell contains "第" and "页" if (secondCell && secondCell.innerText.trim().includes('第') && secondCell.innerText.trim().includes('页')) { // Extract the page number from the second cell(- 15359 表示减去前卷页码,+ 29 表示对页码加以调整以适应实际文件) const pageNumber = parseInt(secondCell.innerText.match(/\d+/)[0]) - 15359 + 29; // Generate the page link const pageLink = `file:///D:/hanyudacidian11.pdf#page=${pageNumber}`; // Create the link element and add it to the second cell const link = document.createElement('a'); link.href = pageLink; link.target = '_blank'; link.innerHTML = secondCell.innerText.trim(); secondCell.innerHTML = ''; secondCell.appendChild(link); } } } }); })(); } if (window.location.href.startsWith("http://www.guoxuedashi.net/")) { //《汉语大词典》第12卷 (function() { 'use strict'; // Find all table rows const tableRows = document.querySelectorAll('table tr'); // Loop through all table rows tableRows.forEach(row => { // Find the first table cell of the row const firstCell = row.querySelector('td:first-child'); // Check if the first cell contains "汉语大词典" if (firstCell && firstCell.innerText.trim() === '汉语大词典') { // Find the third table cell of the row const thirdCell = row.querySelector('td:nth-child(3)'); // Check if the third cell contains "第12卷" if (thirdCell && thirdCell.innerText.trim().includes('第12卷')) { // Find the second table cell of the row const secondCell = row.querySelector('td:nth-child(2)'); // Check if the second cell contains "第" and "页" if (secondCell && secondCell.innerText.trim().includes('第') && secondCell.innerText.trim().includes('页')) { // Extract the page number from the second cell(- 16801 表示减去前卷页码,+ 29 表示对页码加以调整以适应实际文件) const pageNumber = parseInt(secondCell.innerText.match(/\d+/)[0]) - 16801 + 29; // Generate the page link const pageLink = `file:///D:/hanyudacidian12.pdf#page=${pageNumber}`; // Create the link element and add it to the second cell const link = document.createElement('a'); link.href = pageLink; link.target = '_blank'; link.innerHTML = secondCell.innerText.trim(); secondCell.innerHTML = ''; secondCell.appendChild(link); } } } }); })(); } if (window.location.href.startsWith("https://dict.variants.moe.edu.tw/variants/rbt/query_by_standard_tiles.rbt?command=clear")) { // 异体字字典自动粘贴搜索 (function() { 'use strict'; async function pasteClipboard(){ var searchBox = document.getElementsByName("searchedText")[0]; // 获取搜索框 var clipboardText = await navigator.clipboard.readText(); searchBox.value = clipboardText; } pasteClipboard(); var searchBtn = document.querySelector("img[src='images/btn/btn_standard-search.gif']"); // 获取搜索按钮 setTimeout (function() { searchBtn.click(); }, 1000); setTimeout (function() { var wordList = document.querySelector('a[id]'); // 获取搜索结果 wordList.click(); }, 2500); })(); } if (window.location.href.startsWith("https://humanum.arts.cuhk.edu.hk/Lexis/lexi-can/")) { // 粤语审音配词字库自动粘贴搜索 window.onload=function(){ // 获取搜索框和搜索按钮的元素 var searchInput,searchBtn; searchInput = document.querySelector("body > form:nth-child(1) > input[type=text]:nth-child(5)"); searchBtn = document.querySelector("body > form:nth-child(1) > input[type=submit]:nth-child(6)"); if(searchInput){ searchInput.focus(); navigator.clipboard.readText().then(value => { searchInput.value=value; if(searchBtn){ searchBtn.click();} }); } }; }