Advertisement
Guest User

Texthooker Enhanced (for Clipboard Inserter)

a guest
Jul 15th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.13 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Texthooker Enhanced</title>
  6. <!--
  7. /////////////////////////////////////////////////////////////////////
  8. /////////// Texthooker Enhanced for Clipboard Inserter //////////////
  9. /////////////////////////////////////////////////////////////////////
  10.  
  11. Original script was from: https://pastebin.com/raw/HxjV6YrB, which was from the guide: https://pastebin.com/gNJfqpmN
  12.  
  13. Non-default Clipboard Inserter settings are required:
  14. - element name: pre
  15. - container selector: #textlines
  16.  
  17. Use it as is, modify it for your use case or delete it.
  18.  
  19. License: WTFPL
  20.  
  21. /////////////////////////////////////////////////////////////////////
  22. /////////////////////////////////////////////////////////////////////
  23. /////////////////////////////////////////////////////////////////////
  24. -->
  25. <style type="text/css">
  26. body {
  27. background-color: #202020;
  28. color: #BCBCBC;
  29. font-size: 1.2em;
  30. font-weight: 400;
  31. line-height: 150%;
  32. margin-top: 5%;
  33. margin-left: 15%;
  34. margin-right: 15%;
  35. /*margin-left: 640px;
  36. margin-right: 8%;
  37. margin-bottom: 15%;*/
  38. margin-bottom: 500px;
  39. font-family: "IPAGothic", "Sazanami Gothic", "Kochi Gothic", "VL Gothic", "Ume Gothic", "Pro W3", "Hiragino Kaku Gothic Pro", "Osaka Mono", "Osaka", "MS Gothic", "Meiryo", "M+ 1m";
  40. }
  41.  
  42. /* Main text style is here */
  43. pre {
  44. /*font-family: "IPAGothic", "Sazanami Gothic", "Kochi Gothic", "VL Gothic", "Ume Gothic", "Pro W3", "Hiragino Kaku Gothic Pro", "Osaka Mono", "Osaka", "MS Gothic", "Meiryo", "M+ 1m";*/
  45. font-family: "Segoe UI";
  46. white-space: pre-wrap;
  47. padding-bottom: 6px;
  48. }
  49.  
  50. .buttoncontainer {
  51. position: fixed;
  52. top: 3px;
  53. right: 5px;
  54. display: inline-block;
  55. font-size: 1.4em;
  56. font-family: "VL Gothic";
  57. user-select: none;
  58. }
  59.  
  60. .buttoncontainer>div:not(#counter):hover {
  61. filter: brightness(130%);
  62. }
  63.  
  64. #textlines>pre {
  65. /*white-space: pre;*/
  66. border-bottom: #444444 solid 1px;
  67. }
  68.  
  69. #counter {
  70. background-color: rgba(25, 25, 25, 0.5);
  71. color: #9d9d9d;
  72. font-size: 13px;
  73. line-height: 100%;
  74. float: left;
  75. padding-left: 8px;
  76. padding-right: 8px;
  77. padding-top: 5px;
  78. padding-bottom: 6px;
  79. }
  80.  
  81. #clear_button {
  82. background-color: rgba(25, 25, 25, 0.5);
  83. color: #9d9d9d;
  84. font-size: 12px;
  85. line-height: 100%;
  86. float: left;
  87. margin-right: 8px;
  88. padding-left: 8px;
  89. padding-right: 8px;
  90. padding-top: 5px;
  91. padding-bottom: 7px;
  92. cursor: pointer;
  93. cursor: hand;
  94. }
  95.  
  96. #remove_button {
  97. background-color: rgba(25, 25, 25, 0.5);
  98. color: #9d9d9d;
  99. font-size: 24px;
  100. line-height: 100%;
  101. float: right;
  102. margin-right: 10px;
  103. padding-left: 5px;
  104. padding-right: 5px;
  105. padding-top: 5px;
  106. padding-bottom: 5px;
  107. cursor: pointer;
  108. cursor: hand;
  109. }
  110.  
  111. #go_to_last_button {
  112. position: relative;
  113. bottom: -20px;
  114. width: 50px;
  115. cursor: pointer;
  116. user-select: none;
  117. font-size: 50px;
  118. filter: opacity(20%);
  119. }
  120.  
  121. #go_to_last_button:hover {
  122. filter: opacity(40%);
  123. }
  124.  
  125. #go_bottom_button {
  126. position: absolute;
  127. top: 16px;
  128. width: 50px;
  129. cursor: pointer;
  130. user-select: none;
  131. font-size: 50px;
  132. filter: opacity(20%);
  133. }
  134.  
  135. #go_bottom_button:hover {
  136. filter: opacity(40%);
  137. }
  138.  
  139. /* Hover CSS */
  140. .hoverButtonsContainer:hover,
  141. pre:hover>.hoverButtonsContainer>.hoverButtonsBackground {
  142. display: flex !important;
  143. }
  144.  
  145. .hoverButtonsBackground:hover {
  146. filter: opacity(80%);
  147. }
  148.  
  149. .hoverButtonsBackground {
  150. position: absolute;
  151. display: flex;
  152. flex-direction: row;
  153. justify-content: space-evenly;
  154. background-color: rgba(0, 0, 0, .2);
  155. padding: 2px 5px 5px 10px;
  156. border-radius: 0.3vw;
  157. z-index: 555;
  158. filter: opacity(35%);
  159. font-size: 14px;
  160. margin-left: -6px;
  161. margin-top: -2px;
  162. user-select: none;
  163. display: none;
  164. }
  165.  
  166. .hoverButtonsContainer {
  167. position: absolute;
  168. width: 138px;
  169. height: 30vh;
  170. display: flex;
  171. background-color: transparent;
  172. margin-left: -138px !important;
  173. margin-top: 0px;
  174. user-select: none;
  175. }
  176.  
  177. .hoverButtons {
  178. cursor: pointer;
  179. margin-right: 0px;
  180. color: #adadad;
  181. }
  182.  
  183. .hoverButtons:hover {
  184. color: #fff;
  185. }
  186.  
  187. .hoverButtonDelete {
  188. font-size: 25px;
  189. line-height: 28px;
  190. margin-right: 4px;
  191. margin-top: -1px;
  192. }
  193.  
  194. .hoverButtonDown,
  195. .hoverButtonUp {
  196. font-size: 22px;
  197. }
  198.  
  199. .hoverButtonReduceNewlines {
  200. font-size: 33px;
  201. line-height: 22px;
  202. font-family: Arial;
  203. margin-top: 4px;
  204. margin-right: 2px;
  205. }
  206.  
  207. .hoverButtonCopy:hover {
  208. filter: contrast(170%);
  209. }
  210.  
  211. .hoverButtonCopy {
  212. font-size: 20px;
  213. line-height: 22px;
  214. font-family: Arial;
  215. margin-top: 4px;
  216. filter: contrast(90%);
  217. }
  218.  
  219. </style>
  220. <!------------------------
  221.  
  222.  
  223. To change background color or text color, just replace the style values above with the hex values for the colors you want.
  224. If you want the background of the counter to remain semi-transparent, you must use rgb values like above. The last number (where I've put 0.8) is the opacity level (1.0 = completely opaque).
  225. To change font size, just change the em value to what works for you (the standard size is 1, I like it at 1.5).
  226. To change font weight (boldness), just edit the value above. 100 is quite thin, 400 is default, 900 is quite thick. You may want it higher than default for Mincho fonts.
  227. The line-height value changes the spacing between lines.
  228.  
  229. To use the font of your choice, remove the list of fonts above and put the ENGLISH name of your font in quotation marks (some JP font names are in Japanese, such as "三次元切絵字").
  230. Be sure to leave a semi-colon at the end of the line.
  231. To find the English name of a given font, first install it, then open Firefox.
  232. Go to about:preferences#content in the address bar, then click on the 'Default font' drop-down menu.
  233. The "correct" name of your font will be listed here - just copy that down and paste it up above.
  234.  
  235. Note that if you would like to use your browser default font, replace the font-family line with font-family:""; or delete it altogether.
  236. Your default is probably Gothic - if you want to try out a good Mincho font, try Aozora Mincho at http://www.freejapanesefont.com/aozora-mincho-download/
  237. For various other free Japanese fonts, visit http://www.freejapanesefont.com/
  238. For more font attribute information visit http://www.w3schools.com/css/css_font.asp
  239.  
  240. ------------------------>
  241. </head>
  242.  
  243. <body>
  244. <div id="go_bottom_button" title="Scroll to the bottom">🡻</div>
  245.  
  246. <div class="buttoncontainer">
  247.  
  248. <!-- This is the div used for the "remove last line" button. -->
  249. <div id="remove_button" title="Remove last line">✖</div>
  250.  
  251. <!-- This is the div used for the "Clear all lines" button. -->
  252. <div id="clear_button" title="Clear all lines">🗑️</div>
  253.  
  254. <!-- This is the div used for the counter. -->
  255. <div id="counter" title="No. of characters / No. of lines">0 / 0</div>
  256.  
  257. </div>
  258.  
  259. <div style="display:none;">
  260. <!-- Dummy div for buttons-->
  261.  
  262. </div>
  263.  
  264. <!-- jQuery is NOT needed anymore for the page to run. You can change this to an offline version if you prefer. -->
  265.  
  266. <!--
  267. <script src="jquery.min.js"></script>
  268. -->
  269.  
  270. <script>
  271. var domdebug = "";
  272. document.addEventListener("DOMContentLoaded", function(event) {
  273.  
  274. //check document.location.hash at the start to set margins
  275. if (document.location.hash == "#lessmargins") {
  276. var newstyle = document.createElement("style");
  277. newstyle.innerHTML = `
  278. body {
  279. margin-top: 1%;
  280. margin-left: 1%;
  281. margin-right: 1%;
  282. margin-bottom: 5%;
  283. }
  284. `;
  285. document.head.append(newstyle);
  286. }
  287.  
  288.  
  289. //This listens for a node (line) to be inserted.
  290. document.addEventListener("DOMNodeInserted", function(dom) {
  291.  
  292. // console.log(dom);
  293. // domdebug = dom;
  294. //return if the inserted node is not in #textlines
  295. var relatedId = "";
  296. try {
  297. relatedId = dom.relatedNode.attributes.id.value;
  298. } catch (error) {}
  299. if (relatedId != "textlines") {
  300. return
  301. }
  302.  
  303.  
  304. updateCounter();
  305.  
  306. element = dom.target;
  307. //put the added pre text into a span so we can modify it later on.
  308. element.innerHTML = "<span>" + element.innerHTML + "</span>";
  309.  
  310.  
  311. //add hover buttons to every line
  312. createhoverButtons(element);
  313.  
  314. //Scroll to item
  315. scrollToLast();
  316.  
  317. }, false);
  318.  
  319. //End of scroller and counter script.
  320.  
  321. //Beginning of "remove last line" script.
  322. //Listen for click.
  323. document.getElementById("remove_button").addEventListener("click", function() {
  324.  
  325. //Check whether there are any lines.
  326. var remove_lines = document.querySelectorAll('#textlines > pre').length;
  327. if (remove_lines > 0) {
  328.  
  329. //Remove the last line.
  330. document.querySelector("#textlines > pre:last-of-type").remove();
  331.  
  332. updateCounter();
  333. };
  334. });
  335. //End of "remove last line" script.
  336.  
  337. document.getElementById("clear_button").addEventListener("click", function() {
  338. document.querySelectorAll('#textlines')[0].innerHTML = "";
  339. //Update the counter.
  340. updateCounter();
  341. });
  342.  
  343. document.getElementById("go_to_last_button").addEventListener("click", function() {
  344. //document.querySelector("#textlines > pre:last-of-type").scrollIntoView();
  345. window.scroll(0, findPos(document.querySelector("#textlines > pre:last-of-type"))[1] - 280);
  346. });
  347.  
  348.  
  349. document.getElementById("go_bottom_button").addEventListener("click", function() {
  350. document.querySelectorAll("html")[0].scrollIntoView(false);
  351. });
  352.  
  353. /*
  354. debugtest = true;
  355. if (debugtest) {
  356. pre = document.createElement("pre");
  357. pre.innerHTML = "loremipsum\n\nkanjimuzukashikutewakaranai\n\n\n\nwillneverlearn";
  358. document.querySelector("#textlines").append(pre);
  359. }
  360. */
  361. });
  362. //---DOMContentLoaded end---
  363.  
  364. //Used functions
  365. function scrollToLast() {
  366. window.scroll(0, findPos(document.querySelector("#textlines > pre:last-of-type"))[1] - 280);
  367. }
  368.  
  369.  
  370. function scrollUpDown(element, clientY, scrollUp) {
  371. //get the pre
  372. element = element.parentNode.parentNode.parentNode;
  373. var scrollto = null;
  374. try {
  375. if (scrollUp) {
  376. scrollto = element.previousElementSibling;
  377. } else {
  378. scrollto = element.nextElementSibling;
  379. }
  380. if (scrollto == null) {
  381. if (scrollUp) {
  382. document.querySelectorAll("html")[0].scrollIntoView(true);
  383. } else {
  384. document.querySelectorAll("html")[0].scrollIntoView(false);
  385. }
  386. } else {
  387. //fix scroll difference from reality
  388. scrollamount = -16;
  389. window.scroll(0, findPos(scrollto)[1] - clientY - scrollamount);
  390. //scrollto.scrollIntoView();
  391. }
  392. return;
  393. } catch (error) {
  394. //console.log(error);
  395. }
  396. }
  397.  
  398. //find an element's position in the whole page
  399. function findPos(obj) {
  400. var curleft = curtop = 0;
  401. if (obj.offsetParent) {
  402. do {
  403. curleft += obj.offsetLeft;
  404. curtop += obj.offsetTop;
  405. } while (obj = obj.offsetParent);
  406. values = [curleft, curtop];
  407. return values;
  408. }
  409. }
  410.  
  411. function removeLine(element) {
  412. element = element.parentNode.parentNode.parentNode;
  413. element.remove();
  414. updateCounter();
  415. }
  416.  
  417. function reduceNewlines(element) {
  418. element = element.parentNode.parentNode.parentNode;
  419.  
  420. var modifystring = element.querySelector("span").innerText;
  421. //clean spaces
  422. modifystring = modifystring.replace(/\n[\r\t\f\v  \u00a0]*/gm, "\n");
  423. //reduce newlines
  424. modifystring = modifystring.replace(/(\n(\n+?))|(\n+?)/gm, "$2$3");
  425. element.querySelector("span").innerText = modifystring;
  426. }
  427.  
  428. function updateCounter() {
  429. var charlength = 0;
  430. var linecount = 0;
  431. try {
  432. document.querySelectorAll("#textlines > pre").forEach(element => {
  433. charlength += element.innerText.length;
  434. linecount++;
  435. });
  436. } catch (error) {
  437.  
  438. }
  439. document.querySelector("#counter").textContent = charlength + ' / ' + linecount;
  440. return;
  441. }
  442.  
  443. function createhoverButtons(element) {
  444.  
  445. var hoverButtons = document.createElement("div");
  446. element.prepend(hoverButtons);
  447. hoverButtons.outerHTML = `<div class="hoverButtonsContainer">
  448. <div class="hoverButtonsBackground">
  449. <div class="hoverButtons hoverButtonDelete" title="Remove line">✖</div>
  450. <div class="hoverButtons hoverButtonReduceNewlines" title="Reduce newlines and spaces">≡</div>
  451. <div class="hoverButtons hoverButtonCopy" title="Copy to clipboard">📋</div>
  452. <div class="hoverButtons hoverButtonDown" title="Scroll down one line">🡻</div>
  453. <div class="hoverButtons hoverButtonUp" title="Scroll up one line">🡹</div>
  454. </div>
  455. </div>`;
  456. element.querySelector(".hoverButtonDelete").addEventListener("click", function(event) {
  457. removeLine(event.target);
  458. });
  459. element.querySelector(".hoverButtonReduceNewlines").addEventListener("click", function(event) {
  460. reduceNewlines(event.target);
  461. });
  462. element.querySelector(".hoverButtonUp").addEventListener("click", function(event) {
  463. scrollUpDown(event.target, event.clientY, true);
  464. });
  465. element.querySelector(".hoverButtonDown").addEventListener("click", function(event) {
  466. scrollUpDown(event.target, event.clientY, false);
  467. });
  468. element.querySelector(".hoverButtonCopy").addEventListener("click", function(event) {
  469. var range = document.createRange();
  470. console.log(event.target.parentNode.parentNode.parentNode.querySelector("span"));
  471. range.selectNode(event.target.parentNode.parentNode.parentNode.querySelector("span"));
  472. window.getSelection().removeAllRanges();
  473. window.getSelection().addRange(range);
  474. document.execCommand("copy");
  475. window.getSelection().removeAllRanges();
  476. });
  477.  
  478.  
  479. }
  480.  
  481. </script>
  482.  
  483. <!-- inserted pre tags go here -->
  484. <div id="textlines">
  485. </div>
  486.  
  487. <div id="go_to_last_button" title="Scroll to the start of the last item">🡹</div>
  488. </body>
  489.  
  490. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement