论语网站js

在该网站上对一条《论语》ctrl+右键可在右侧看到相应翻译。

目前为 2021-08-13 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 论语网站js
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 在该网站上对一条《论语》ctrl+右键可在右侧看到相应翻译。
  6. // @author Pikaqian
  7. // @match https://lunyu.5000yan.com/
  8. // @icon https://5000yan.com/templets/default/lunyu/favicon.ico
  9. // @grant GM_xmlhttpRequest
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. var style=document.createElement("style"),background
  15. style.textContent=`
  16. #newElement{
  17. display:block;
  18. position:fixed;
  19. background-color:#fff;
  20. width:264px;
  21. height:500px;
  22. top:5px;
  23. padding:10px;
  24. transition:0.3s;
  25. right:-400px
  26. }
  27. #background{
  28. display:block;
  29. position:fixed;
  30. background-color:#fff;
  31. width:264px;
  32. height:500px;
  33. transition:0.5s
  34. }
  35. #out_title{
  36. color: #000;
  37. display: block;
  38. position: fixed;
  39. z-index: 1;
  40. font-weight: 1000;
  41. transform: translate(10px,5px)
  42. }
  43. #out_content{
  44. color:#000;
  45. display: block;
  46. position: fixed;
  47. z-index: 1;
  48. width:246px;
  49. transition: 0.2s;
  50. font-size:15px;
  51. transform: translate(10px,50px)
  52. }
  53. #line{
  54. display:block;
  55. position:fixed;
  56. background-color:#000;
  57. width:249px;
  58. opacity:0.5;
  59. transform: translate(7px, 37px);
  60. z-index:1;
  61. height:1.5px
  62. }
  63. `
  64. document.body.appendChild(style)
  65. function addRightButton(){
  66. var newElement=document.createElement("div")
  67. newElement.id="newElement"
  68. document.body.appendChild(newElement)
  69.  
  70.  
  71. var line = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  72. line.setAttribute('viewbox', '0 0 24 24');
  73. line.setAttribute('width', '24px');
  74. line.setAttribute('height', '24px');
  75. line.id = 'line';
  76. document.getElementById("newElement").appendChild(line);
  77.  
  78.  
  79.  
  80. var background=document.createElement("background")
  81. background.type="text"
  82. var out_title=document.createElement("out_title")
  83. out_title.id="out_title"
  84. var title=document.createTextNode("句子翻译");
  85.  
  86. var out_content=document.createElement("out_content")
  87. out_content.id="out_content"
  88. var content=document.createTextNode("222");
  89. out_content.style.top="10px"
  90.  
  91. document.getElementById("newElement").appendChild(out_title);
  92. document.getElementById("newElement").appendChild(out_content);
  93. document.getElementById("out_title").appendChild(title);
  94. document.getElementById("out_content").appendChild(content);
  95.  
  96. background.setAttribute("aria-hidden","true");
  97. background.setAttribute('viewbox', '0 0 24 24');
  98. background.id = 'background';
  99. document.getElementById("newElement").appendChild(background);
  100. }
  101. addRightButton()
  102.  
  103.  
  104. window.addEventListener('contextmenu',function(event){
  105.  
  106. if(event.ctrlKey==true&&event.target.parentNode.parentNode.className=="shouye"){
  107. var event_href=event.target.href
  108. GM_xmlhttpRequest({
  109. method: "GET",
  110. url: event_href,
  111. headers:{
  112. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.67"
  113. },
  114. onload: function(res) {
  115. if(res.status === 200){
  116. console.log('成功')
  117. var p=res.responseText
  118. //console.log(p)
  119. var first=p.match('name="description"').index
  120. var last=p.match('<title>').index
  121. var translate=p.substring(first+28,last-6)
  122. //console.log(translate)
  123.  
  124. document.getElementById("out_content").style.opacity="0"
  125. setTimeout(function(){
  126. document.getElementById("out_content").innerText=translate
  127. },150)
  128. setTimeout(function(){
  129. document.getElementById("out_content").style.opacity="1"
  130. },150)
  131. var back=document.getElementById("newElement")
  132. back.style.transform="translateX(-409px)"
  133. }
  134. else{
  135. console.log('失败')
  136. console.log(res)
  137. //fail()
  138. }
  139. }
  140. })
  141. event.preventDefault()
  142. }
  143. })
  144. })();

QingJ © 2025

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