word copy demo🔧

a private tool

  1. // ==UserScript==
  2. // @name word copy demo🔧
  3. // @description a private tool
  4. // @namespace word_copy_tool_demo
  5. // @author Covenant
  6. // @version 1.0.4
  7. // @license MIT
  8. // @homepage
  9. // @match *://*/*
  10. // @exclude https://codepen.io/*
  11. // @exclude file:///*
  12. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADQAAAA0CAMAAADypuvZAAAAPFBMVEUAAACvDwOyDwKyDwOvEACyDgOyDwKvDwKwDgCyDgKxDgOyDgKvDgKyDwKyDgOxDgKzDgKxDgKxEASyDwMgW5ZmAAAAE3RSTlMAQN+/EJDvMB9wYJ9Qz7CAf6CAtGoj/AAAAcFJREFUSMeVltu2gyAMRLlfBDxt+f9/PTq2VXSwmod2GdhkEoIiiPmYinK1VqXt4MUFk9bVxlTyvxBdienhNoJwoYMY+57hdMzBTA4v4/gRaykT1FuLNI0/j/1g3i2IJ8s9F+owNCx+2UlWQXbexQFjjTjN1/lGALS9xIm9QIXNOoowlFKrFssYTtmvuOXpp2HtT6lUE3f11bH1IQu9qbYUBEr7yq8zCxkWuva8+rtF4RrkP6ESxFPoj7rtW30+jI4UQlZuiejEwZ4cMg65RKjjUDz6NdwWvxw6nnLESEAl230O5cldUAdy8P44hJZTYh40DOIKzFw3QOI6hPk9aDiFHJc3nMirKERgEPd7FKKgiy5DEn3+5JsrAfHNtfjVRLucTPTaCA1rxFVz6AX8yYsIUlXoMqbPWFUeXF1Cyqz7Ej1PAXNBs1B1tsKWKpsX0yFhslTetL4mL8s4j2fyslTbjbT7Va2V7GCG5ukhftijXdsoQhGmzSI4QhHGhVufz4QJ/v6Hug6dK0EK3YuM8/3Lx5h3Z0STywe55oxRejM5Qo4aAtZ8eTBuWp6dl3IXgfnnLpyzBCFctHomnSopejLhH/3AMfEMndTJAAAAAElFTkSuQmCC
  13. // @grant GM_setValue
  14. // @grant GM_getValue
  15. // @grant GM_registerMenuCommand
  16. // @grant GM_listValues
  17. // @connect
  18. // @run-at document-end
  19. // @noframes
  20. // ==/UserScript==
  21. var style_font_face;
  22. var style_user_css;
  23. var div_fixed;
  24. var input_word;
  25. var select_idx;
  26. var input_num;
  27. var btn_copy;
  28. var p_console_log;
  29. var novel_text_raw="_null";
  30. var object_URL;
  31. var str_title;
  32. const str_xhtml_epub3_start=`<?xml version="1.0" encoding="utf-8"?>
  33. <!DOCTYPE html>
  34.  
  35. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
  36. <head>
  37. <title></title>
  38. <link href="../Styles/Style0001.css" type="text/css" rel="stylesheet"/>
  39. </head>
  40.  
  41. <body>
  42. `;
  43. const str_xhtml_epub3_end=`</body>
  44. </html>`;
  45. if(document.body!=null&&document.head!=null){
  46. str_title="<h2>"+fn_slice(document.querySelectorAll("head>title")[0].innerText,GM_getValue('trim_title_head',0),GM_getValue('trim_title_end',0))+"</h2>\n";
  47. }
  48. function create_style(textContent,id,class_name){let style=create_style_iframes(textContent,id,class_name,document.body);return style;}
  49. const str_font_mono="'Noto Sans Mono','Noto Mono','Cascadia Mono','Consolas','Droid Sans Mono','Liberation Mono','Monaco','Noto Sans Mono CJK JP','NotoMono_CJK','Courier New',";
  50. const str_font_code="'code_ligature','NotoMono_Slim','Noto Sans Mono','Noto Mono','Cascadia Code','Consolas','Droid Sans Mono','Liberation Mono','Monaco','Courier New',";
  51. const str_font_sans_ja="'Noto Sans CJK JP','Meiryo','Yu Gothic','Microsoft JhengHei',";
  52. const str_font_emoji_end="'symbol_sans','symbol2_sans','emoji_back',",str_font_symbol_end="'symbol_sans','symbol2_sans','color_emoji','emoji_back',";
  53. const font_family_panel="font-family: 'manga_kana',"+str_font_mono+str_font_sans_ja+str_font_symbol_end+"monospace;";
  54. const font_family_code="font-family: 'emoji_patch','Firple Slim',"+str_font_code+"'color_emoji',"+str_font_sans_ja+str_font_emoji_end+"monospace;";
  55. const font_family_panel_important="font-family: 'Noto Sans Mono','Noto Mono','Cascadia Mono','Consolas','Liberation Mono','Monaco','Courier New','flag_patch','flag_white_patch','Noto Sans CJK JP','Meiryo','Yu Gothic','Microsoft JhengHei','symbol_sans','symbol2_sans','color_emoji','emoji_back',monospace !important;";
  56. const font_face_default=`
  57. @font-face{font-family: 'color_emoji';src: local('Twemoji Mozilla'),local('Noto Color Emoji'),local('Segoe UI Emoji'),local('Apple Color Emoji');}
  58. @font-face{font-family: 'symbol_sans';src: local('Segoe UI Symbol'),local('NotoSansSymbols-Regular'),local('NotoSansSymbols-Regular-Subsetted'),local('Noto Sans Symbols'),local('Apple Symbols'),local('Meiryo');}
  59. @font-face{font-family: 'symbol2_sans';src: local('NotoSansSymbols2-Regular'),local('NotoSansSymbols-Regular-Subsetted2'),local('Symbola');}
  60. @font-face{font-family: 'emoji_back';src: local('Noto Color Emoji'),local('Toss Face Font Web'),local('Segoe UI Emoji');}
  61. @font-face{font-family: 'DroidSans_Mono';src: local('DroidSansMono');}\n@font-face{font-family: 'Cutive_Mono';src: local('Cutive Mono');}
  62. @font-face{font-family: 'Roboto_Regular';src: local('Roboto');}\n@font-face{font-family: 'Noto_Serif';src: local('NotoSerif');}
  63. @font-face{font-family: 'Dancing_Script';src: local('DancingScript'),local('DancingScript-Regular');}\n@font-face{font-family: 'Coming_Soon';src: local('ComingSoon'),local('ComingSoon-Regular');}
  64. @font-face{font-family: 'Carrois_GothicSC';src: local('CarroisGothicSC-Regular');}\n@font-face{font-family: 'NotoMono_CJK';src: local('Noto Sans Mono CJK JP'),local('NotoSansMonoCJKjp-Regular');}\n`;
  65. if(document.body!=null){
  66. style_font_face=create_style(font_face_default,"gm_font_face_word_copy_demo",["user_gm_css","css_word_copy_demo"]);
  67. style_user_css=create_style(".user_input_fixed_novel,.user_opt_fixed_novel,.p_console_log{"+font_family_panel_important+"font-weight: 300;}\n","gm_user_css_word_copy_demo",["user_gm_css","css_word_copy_demo"]);//questions/2570972/
  68. style_user_css.textContent+=`input.user_input_fixed_novel{width: auto;max-width: 95%;border-radius: 0.5rem; font-size: 110%;padding: 0.25em;max-height: 2em;}
  69. .user_btn_panel_fixed_novel,.user_a_panel_fixed_novel{min-width: 5em;min-height: 1em;max-height: 2em;`+font_family_panel_important+`font-weight: 400;}
  70. .user_a_panel_fixed_novel{display: inline-block;text-align: center;border-style: dashed;border-width: 1px;}
  71. .user_select_fixed_novel{font-size: 0.75rem;padding: 0.25rem;min-width: 5em;max-width: 7em;}
  72. .input_querySelectorAll_novel{min-width: 32rem;}\n.p_console_log{background: #00000080;}
  73. input[type="checkbox"].user_checkbox~label{margin-right: 0.5em;cursor: pointer;}\ndiv.div_checkbox{min-width: 2em;background: #00000080;}\ndiv.user_checkbox_inline{display: inline-block;}
  74. .user_btn_margin{margin-right: 2px;margin-left: 3px;margin-top: 1px;margin-bottom: 1px;padding: 0.1rem 0.5rem;}
  75. .text_border{color: #000000;text-shadow: -1px -1px 0px #FFFFFF,0px -1px 0px #FFFFFF,1px -1px 0px #FFFFFF,-1px 0px 0px #FFFFFF,1px 0px 0px #FFFFFF,-1px 1px 0px #FFFFFF,0px 1px 0px #FFFFFF,1px 1px 0px #FFFFFF;}
  76. .display_none{display: none;}
  77. .inline_block{display: inline-block;}\ndiv.div_br{width: 100%;}
  78. .user_div_fixed_novel{position:fixed !important;z-index: 65535;top: 40%;right: 0px;}
  79. .user_div_fixed_novel{background: #00000033;min-width: 50%;max-width: 75vw;}
  80. .user_div_fixed_novel *{direction: ltr;}
  81. .rtl.rtl.rtl.rtl,.user_div_fixed_novel.user_div_fixed_novel.user_div_fixed_novel.user_div_fixed_novel{direction: rtl;}\n`;
  82. }
  83. function create_div(class_name,is_appendChild,node,refNode){
  84. let div=create_node("div",class_name,is_appendChild,node,refNode);
  85. div.style.backgroundSize='contain';
  86. div.style.backgroundRepeat='no-repeat';
  87. div.lang='ja';
  88. return div;
  89. }
  90. function create_input(placeholder,class_name,is_num,is_appendChild,node,refNode){
  91. let input=create_node("Input",class_name,is_appendChild,node,refNode);
  92. input.placeholder=placeholder;
  93. input.type="text";
  94. if(is_num)input.size="10";
  95. if(is_num)input.setAttribute("maxlength", "10");
  96. //if(is_num)input.setAttribute("oninput","this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\\..*?)\\..*/g, '$1');");
  97. if(is_num){
  98. input.addEventListener("input", function (e){
  99. this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');
  100. });
  101. input.style.setProperty("text-align", "right");
  102. }return input;
  103. }
  104. function create_btn(innerText,class_name,is_appendChild,node,refNode){
  105. let btn=create_node_text("button",innerText,class_name,is_appendChild,node,refNode);
  106. return btn;
  107. }
  108. function create_a(innerText,url,class_name,is_appendChild,node,refNode){
  109. let anchor=create_node_text("a",innerText,class_name,is_appendChild,node,refNode);
  110. anchor.href=url;
  111. anchor.title=innerText;
  112. if(url.search(new RegExp("javascript", "i"))!=0||url.indexOf(":")!=10)anchor.target="_blank";
  113. return anchor;
  114. }
  115. function create_select(class_name,is_multiple,size,is_appendChild,node,refNode){
  116. let select=create_node("select",class_name,is_appendChild,node,refNode);
  117. select.setAttribute("multiple", is_multiple);
  118. select.setAttribute("size", size);
  119. return select;
  120. }
  121. function create_checkbox(innerText,id,is_block,is_checked,class_name,is_appendChild,node,refNode){
  122. const div_class=is_block?"div_checkbox":["div_checkbox","user_checkbox_inline"];
  123. let div=create_div(div_class,is_appendChild,node,refNode);
  124. let input=create_node("Input",class_name,true,div);
  125. input.type="checkbox";
  126. input.id="cb_"+id;
  127. input.value=id;
  128. if(is_checked==true)input.checked=true;
  129. let lbl=create_node_text("label",innerText,"user_lbl",true,div);
  130. lbl.htmlFor=input.id;
  131. return input;
  132. }
  133. function create_style_iframes(textContent,id,class_name,node){
  134. let style=create_node("style",class_name,true,node);
  135. style.type='text/css';
  136. style.id=id;
  137. style.textContent=textContent;
  138. return style;
  139. }
  140. function create_node(tagname,class_name,is_appendChild,node,refNode){
  141. let element=document.createElement(tagname);
  142. element.id="";
  143. if(Array.isArray(class_name)){
  144. for(let i=0; i<class_name.length; i++){element.classList.add(class_name[i]);}
  145. }else if(typeof class_name==='string'){element.classList.add(class_name);}
  146. if(node==undefined){node=document.body;}
  147. if(is_appendChild){node.appendChild(element);}
  148. else{
  149. if(refNode==undefined){node.insertBefore(element,node.firstChild);}else{node.insertBefore(element,refNode);}
  150. }return element;
  151. }
  152. function create_node_text(tagname,innerText,class_name,is_appendChild,node,refNode){
  153. let element=create_node(tagname,class_name,is_appendChild,node,refNode);
  154. element.innerText=innerText;
  155. element.lang='ja';
  156. return element;
  157. }
  158. function console_log(text,bool){
  159. let div_log=p_console_log;
  160. div_log.innerHTML+=text+" ";
  161. if(bool){div_log.innerHTML+="<br>";}
  162. else if(bool==undefined){div_log.innerHTML=text;}
  163. }
  164. function fn_remove_multiple_line_breaks(str){//questions/22962220
  165. return str.replace(/(\r\n|\r|\n){2}/g, '$1').replace(/(\r\n|\r|\n){3,}/g, '$1\n');
  166. }
  167. function fn_slice(str,head,end){
  168. str=parseInt(end)=="0"?str.slice(head):str.slice(head, parseInt(end)*(-1));
  169. return str;
  170. }
  171. //console.log("break");
  172. function fn_str2xhtml_node(str){
  173. let ary_str=str.split('\n');
  174. let innerHTML="";
  175. for(let i=0; i<ary_str.length; i++){
  176. let element=document.createElement("p");
  177. element.textContent=ary_str[i];
  178. innerHTML+=element.outerHTML+"\n";
  179. }
  180. return innerHTML.replaceAll("&nbsp;","");
  181. }
  182. function fn_str2xhtml_full(str,title){
  183. title=(typeof title==='string')?title:"";
  184. return str_xhtml_epub3_start+title+fn_str2xhtml_node(str)+str_xhtml_epub3_end;
  185. }
  186. function fn_char2u(char){
  187. return "\\u"+("0000"+char.charCodeAt(0).toString(16)).slice(-4);
  188. }
  189. function fn_querySelectorAll(){
  190. try{
  191. let node=document.querySelectorAll(input_word.value);
  192. if(node.length>0){
  193. select_idx.innerText="";
  194. for(let i=0; i<node.length>0; i++){
  195. let count_img=node[i].querySelectorAll('img').length;
  196. let option=create_node("option",["user_opt_fixed_novel"],true,select_idx);
  197. option.value=i;
  198. option.innerText=option.value+(count_img>0?" img["+count_img+"]":"");
  199. }
  200. }else if(node.length==0){
  201. select_idx.innerText="";
  202. let option=create_node("option",["user_opt_fixed_novel"],true,select_idx);
  203. option.innerText="null";
  204. option.setAttribute("disabled", true);
  205. }
  206. }catch(e){
  207. console_log(e.message);
  208. }finally{}
  209. }
  210. function fn_select_idx(){
  211. input_num.value=select_idx.value;
  212. }
  213. function fn_btn_copy(){
  214. console_log("");
  215. try{
  216. console_log(fn_slice(document.querySelectorAll("head>title")[0].innerText,GM_getValue('trim_title_head',0),GM_getValue('trim_title_end',0)),true);
  217. let node=document.querySelectorAll(input_word.value);
  218. if(node.length>0){
  219. let index=input_num.value==""?0:parseInt(input_num.value);
  220. index=node.length>index?index:0;
  221. novel_text_raw=fn_remove_multiple_line_breaks(node[index].innerText);
  222. btn_copy.innerText="copy "+novel_text_raw.length+";";
  223. let str_debug=novel_text_raw.substring(0,7);
  224. for(let i=0; i<str_debug.length>0; i++){
  225. console_log(fn_char2u(str_debug[i]),false);
  226. }
  227. }else if(node.length==0){
  228. novel_text_raw="_null";
  229. btn_copy.innerText="copy null";
  230. }
  231. //navigator.clipboard.writeText(novel_text_raw);
  232. return novel_text_raw;
  233. }catch(e){
  234. console_log(e.message);
  235. }finally{}
  236. }
  237. (function() {
  238. 'use strict';
  239. if(document.body==null)return;
  240. let panel=GM_getValue('panel', false);
  241. let epub=GM_getValue('epub', false);
  242. let is_add_title=GM_getValue('is_add_title', false);
  243. let selector=GM_getValue('selector', "");
  244. let trim_title_head=GM_getValue('trim_title_head', 0);
  245. let trim_title_end=GM_getValue('trim_title_end', 0);
  246. let idx_page=GM_getValue('idx_page', 1);
  247. GM_registerMenuCommand('💬input;', () => {
  248. panel=!panel;
  249. GM_setValue('panel', panel);
  250. if(panel){div_fixed.style.removeProperty("display");}else{div_fixed.style.display="none";}
  251. });
  252. GM_registerMenuCommand('⚠️epub tool panel beta', () => {
  253. epub=!epub;
  254. GM_setValue('epub', epub);
  255. });
  256. //div fixed ui
  257. div_fixed=create_div(["user_div_fixed_novel"],false,document.body,document.body.firstChild);
  258. if(panel){div_fixed.style.removeProperty("display");}else{div_fixed.style.display="none";}
  259. let div_g1=create_div(["inline_block"],true,div_fixed);
  260. input_word=create_input("querySelectorAll(selectors)",["user_input_fixed_novel","input_querySelectorAll_novel"],false,true,div_g1);
  261. create_div("div_br",true,div_fixed);
  262. let div_g2=create_div(["inline_block"],true,div_fixed);
  263. p_console_log=create_node("p",["p_console_log","inline_block"],true,div_g2);
  264. btn_copy=create_btn("copy",["user_btn_panel_fixed_novel","user_btn_margin"],true,div_g2);
  265. select_idx=create_select(["user_select_fixed_novel"],true,"5", true, div_g2);
  266. input_num=create_input("[index]",["user_input_fixed_novel"],true,true,div_g2);
  267. input_num.title="nodeList[index]";
  268. if(epub){
  269. create_div("div_br",true,div_fixed);
  270. let div_g3=create_div(["inline_block"],true,div_fixed);
  271. create_node_text("p","dev tool: ",["p_console_log","inline_block"],true,div_g3);
  272. let checkbox_add_title=create_checkbox("use title at full","",false,is_add_title,[],true,div_g3);
  273. checkbox_add_title.addEventListener('click',(evt)=> {
  274. is_add_title=checkbox_add_title.checked;
  275. GM_setValue('is_add_title', checkbox_add_title.checked);
  276. });
  277. let input_trim_title_head=create_input("0",["user_input_fixed_novel"],true,true,div_g3);
  278. input_trim_title_head.value=trim_title_head;
  279. input_trim_title_head.addEventListener('input',(evt)=> {
  280. GM_setValue('trim_title_head', parseInt(input_trim_title_head.value));
  281. });
  282. let input_trim_title_end=create_input("0",["user_input_fixed_novel"],true,true,div_g3);
  283. input_trim_title_end.value=trim_title_end;
  284. input_trim_title_end.addEventListener('input',(evt)=> {
  285. GM_setValue('trim_title_end', parseInt(input_trim_title_end.value));
  286. });
  287. let btn_xhtml_copy_node=create_btn("xhtml_copy_node",["user_btn_panel_fixed_novel","user_btn_margin","text_border"],true,div_g3);
  288. let btn_xhtml_copy_full=create_btn("xhtml_copy_full",["user_btn_panel_fixed_novel","user_btn_margin","text_border"],true,div_g3);
  289. create_div("div_br",true,div_fixed);
  290. //let btn_download_txt=create_btn("get xhtml",["user_btn_panel_fixed_novel","user_btn_margin","text_border"],true,div_fixed);
  291. let div_g4=create_div([],true,div_fixed);
  292. let input_idx_page=create_input("0",["user_input_fixed_novel"],true,true,div_g4);
  293. input_idx_page.value=idx_page;
  294. input_idx_page.addEventListener('input',(evt)=>{
  295. GM_setValue('idx_page', parseInt(input_idx_page.value));
  296. });
  297. let a_download=create_a("download xhtml","",["user_a_panel_fixed_novel","user_btn_margin","text_border"],true,div_g4);
  298. let btn_scroll_end=create_btn("scroll end",["user_btn_panel_fixed_novel","user_btn_margin"],true,div_g4);
  299. btn_scroll_end.addEventListener('click',() =>{
  300. window.scrollTo(0, document.body.scrollHeight);
  301. });
  302. btn_xhtml_copy_node.addEventListener('click',() =>{
  303. fn_btn_copy();
  304. let tmp=fn_str2xhtml_node(novel_text_raw);
  305. navigator.clipboard.writeText(tmp);
  306. });
  307. btn_xhtml_copy_full.addEventListener('click',() => {
  308. fn_btn_copy();
  309. let tmp=fn_str2xhtml_full(novel_text_raw,is_add_title?str_title:"");
  310. navigator.clipboard.writeText(tmp);
  311. });
  312. /*btn_download_txt.addEventListener('click',() => {
  313. let text = 'hello blob';
  314. let blob = new Blob([text], { type: 'text/plain' });
  315. let textFile = window.URL.createObjectURL(blob);
  316. let window2 = window.open(textFile, 'log.' + new Date() + '.txt');
  317. window2.onload = e => window.URL.revokeObjectURL(textFile);//*/
  318. /*var blob = new Blob(["abc"], {type:"text/plain"});
  319. var reader = new FileReader();
  320. reader.addEventListener("load", function(e) {
  321. // replace existing `MIME` type with `application/octet-stream`
  322. var file = "data:application/octet-stream;"
  323. + e.target.result.split(/;/)[1];
  324. var saveFile = window.open(file, "_self");
  325. });
  326. reader.readAsDataURL(blob)//*/
  327. /*});//*/
  328. a_download.addEventListener('mouseover',(event) => {
  329. window.URL.revokeObjectURL(object_URL);
  330. event.target.title=(new Date());
  331. fn_btn_copy();
  332. let tmp=fn_str2xhtml_full(novel_text_raw,is_add_title?str_title:"");
  333. idx_page=parseInt(input_idx_page.value);
  334. if(novel_text_raw=="_null"){
  335. event.target.href="#";
  336. event.target.target="_self";
  337. }else{
  338. event.target.target="_blank";
  339. let blob = new Blob([tmp], {type: "text/plain"});
  340. object_URL = window.URL.createObjectURL(blob);
  341. event.target.href = object_URL;
  342. event.target.download = "Section"+idx_page.toString().padStart(4,'0')+".xhtml";
  343. }
  344. });
  345. a_download.addEventListener('click',(event) => {
  346. idx_page++;
  347. input_idx_page.value=idx_page;
  348. GM_setValue('idx_page', parseInt(input_idx_page.value));
  349. event.target.innerText+="✔️";
  350. });
  351. }
  352. //
  353. input_word.value=selector;
  354. input_num.value=0;
  355. //console_log_tmp(GM_listValues()+" "+panel,true);
  356. //
  357. input_word.addEventListener("input", function (event) {fn_querySelectorAll();});
  358. fn_querySelectorAll();
  359. select_idx.addEventListener("input", fn_select_idx);
  360. btn_copy.addEventListener('click',() => {
  361. fn_btn_copy();
  362. navigator.clipboard.writeText(novel_text_raw);
  363. });
  364. /*input_word.addEventListener("keyup", function(e){
  365. });//*/
  366. window.addEventListener("beforeunload", (event) => {
  367. // set a truthy value to property returnValue
  368. GM_setValue('selector', input_word.value);
  369. });
  370. })();

QingJ © 2025

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