wiki3d

wiki 3d

  1. // ==UserScript==
  2. // @name wiki3d
  3. // @include *wikipedia*
  4. // @supportURL https://github.com/sxlgkxk/browser_script/issues
  5. // @version 0.3
  6. // @description wiki 3d
  7. // @namespace http://sxlgkxk.github.io/
  8. // @author sxlgkxk
  9. // @icon http://sxlgkxk.github.io/im/avatar.jpg
  10. // @license MIT
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // @grant GM_xmlhttpRequest
  14. // ==/UserScript==
  15.  
  16. /*
  17. 1. 代码功能: wiki内容的3d化
  18.  
  19. */
  20.  
  21. (function () {
  22.  
  23. //-------------------------------- common functions --------------------------------
  24.  
  25. function addScript(src, content='') {
  26. let scripts_dom = document.createElement('script');
  27. if (content){
  28. scripts_dom.textContent = content;
  29. scripts_dom.type = 'module';
  30. } else {
  31. scripts_dom.src = src;
  32. scripts_dom.type = 'text/javascript';
  33. }
  34. document.getElementsByTagName('head')[0].appendChild(scripts_dom);
  35. }
  36. addScript('https://unpkg.com/axios/dist/axios.min.js')
  37. addScript('https://cdn.jsdelivr.net/npm/marked/marked.min.js')
  38.  
  39. function addStyle(html) {
  40. let style = document.createElement("div")
  41. document.body.before(style)
  42. style.innerHTML = `<style>` + html + `</style>`
  43. }
  44.  
  45. //-------------------------------- code snippets --------------------------------
  46.  
  47. //-------------------------------- main --------------------------------
  48.  
  49. let doms=document.querySelector('#bodyContent').querySelectorAll('a')
  50. let urlSet=new Set()
  51. for(let dom of doms){
  52. let url=dom.href
  53. if(url.match(/^https:\/\/en.(m\.)*wikipedia.org\/wiki/)){
  54. if(url.match(/^https:\/\/en.(m\.)*wikipedia.org\/wiki\/.*?([:\(#]|Main_Page|undefined)+.*?/))
  55. continue
  56. if(url == location.href)
  57. continue
  58. urlSet.add(url)
  59. }
  60. }
  61. let urls=Array.from(urlSet)
  62. // urls=urls.sort(()=>Math.random()-0.5)
  63. let content=``;
  64. for(let url of urls){
  65. let name=new URL(url).pathname
  66. content+=`${name}\n`
  67. }
  68.  
  69. //-------------------------------- wrap up --------------------------------
  70.  
  71. // three.js
  72. let scripts_dom = document.createElement('script');
  73. scripts_dom.textContent =`{
  74. "imports": {
  75. "three": "https://unpkg.com/three/build/three.module.js"
  76. }
  77. }`;
  78. scripts_dom.type = 'importmap';
  79. document.getElementsByTagName('head')[0].appendChild(scripts_dom);
  80.  
  81. // dom insert
  82. let three_dom = document.createElement('div')
  83. document.body.before(three_dom)
  84. three_dom.id='three_panel'
  85.  
  86. addScript('', `
  87. // import { wikiInit } from 'https://sxlgkxk.github.io/cdn/3d/mc/mc.js';
  88. import { wikiInit } from 'http://127.0.0.1:4000/cdn/3d/mc/mc.js';
  89. wikiInit("three_panel", \`${content}\`);
  90. `)
  91. addStyle(`
  92. #three_panel {
  93. margin-bottom: 10px;
  94. margin-top: 10px;
  95. }
  96. `)
  97.  
  98.  
  99. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址