Guest User

Original unedited post (loyce backup)

a guest
Sep 18th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Original unedited post (loyce backup)
  3. // @namespace https://bitcointalk.org/
  4. // @version 0.1
  5. // @description popup unedited loyce (original posts) when click on date
  6. // @author 0x256
  7. // @include https://bitcointalk.org/index.php?topic=*
  8. // @grant GM_addStyle
  9.  
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. /* edit_history_min style (css) */
  15. GM_addStyle(".modal{background-color:#fff;z-index:5;position:fixed;top:8%;width:70vw;border-radius:5px;margin-left: -4.5%;}.modal-header{position:relative}.modal-header,.modal-body{padding:10px}.modal-header > h3{margin:0}.modal-close,.diff_btn{cursor:pointer;display:inline-block;position:absolute}.modal-close{padding:10px 20px;top:0;right:0;opacity:0.6}.diff_btn{padding:8px;top:0;right:60px;}.modal-close:hover{opacity:1}.modal-body{background:#ECEDF3;overflow-y: auto;max-height: 500px;}.modal-backdrop{position:fixed;top:0;left:0;width:100vw;height:100vh;background-color:#000;opacity:.3;z-index:4}.modal-body:lang(ar)>.post{direction: rtl}.modal-body>.post>img.icon{float:left;margin-right:8px}");
  16.  
  17.  
  18. // Get the button that opens the modal
  19. let myBtn = document.querySelectorAll(".edited");
  20.  
  21. Array.from(myBtn).forEach((element) => {
  22. element.addEventListener('click', creatModal );
  23. });
  24.  
  25. /** open the modal */
  26. // When the user clicks the date, create and open the modal
  27. function creatModal() {
  28.  
  29. var msgID = (this.parentElement.parentElement.parentElement.querySelector('td+td>div.subject').id).match(/\d+/)[0],
  30. directoryName = msgID.slice(0, -4),
  31. loyceURL = 'https://loyce.club/archive/posts/'+ directoryName +'/'+ msgID +'.html';
  32.  
  33. document.body.style.overflow = "hidden";
  34.  
  35. /* create modal after myBtn */
  36. this.insertAdjacentHTML('afterend', `<div class="modal"><div class="modal-header"><h3>Original unedited post <a target="_blank" href="`+loyceURL+`">(loyce backup link<img src="https://i.ibb.co/yN1t1jW/externallink.png">)</a></h3><span class="diff_btn"><img src="https://i.ibb.co/xgwRWb5/diff-icon.png" title="find difference"></span><span class="modal-close">✖</span></div><div class="modal-body"></div></div><div class="modal-backdrop show"></div>`);
  37.  
  38. // Get the modal
  39. let modal = document.getElementsByClassName("modal")[0];
  40.  
  41. // Get the <span> element that closes the modal
  42. let modalClose = document.getElementsByClassName("modal-close")[0];
  43.  
  44. // Get the modal-body element
  45. let modalBody = document.getElementsByClassName("modal-body")[0];
  46.  
  47. // Get the modal-backdrop
  48. let modalBackdrop = document.getElementsByClassName("modal-backdrop")[0];
  49.  
  50. /*------------------------------------
  51. load loyce unedited backup post
  52. ------------------------------------*/
  53. function load_unedited_post() {
  54. var xhttp = new XMLHttpRequest();
  55. xhttp.onreadystatechange = function() {
  56.  
  57. if (this.readyState < 4 ) {
  58. modalBody.innerHTML = '<div class="post"><img class="loadin icon" src="https://i.ibb.co/5j979m2/loading.gif" alt="loading icon" /> loading please wait ...</div>';
  59. }
  60.  
  61. if (this.readyState == 4 && this.status == 404) {
  62. modalBody.innerHTML = '<div class="post"><img class="warning icon" src="https://i.ibb.co/HVY6PmJ/warning-icon.png" alt="warning icon" /> Sorry, there no unedited backup for this post.</div>';
  63. }
  64.  
  65. if (this.readyState == 4 && this.status == 200) {
  66.  
  67. /*from stackoverflow for test*/
  68. var doc = new DOMParser().parseFromString(this.responseText, 'text/html');
  69. var post = doc.querySelector('.post').innerHTML;
  70.  
  71. modalBody.innerHTML = '<div class="post">'+post+'</div>';
  72.  
  73.  
  74. var edited_post = "";
  75. var unedited_post = post.replace(/<[^>]*>/g, '');
  76. }
  77. };
  78.  
  79. xhttp.open("GET", loyceURL, true);
  80. xhttp.send();
  81.  
  82. }
  83.  
  84. load_unedited_post();
  85.  
  86. /** close the modal */
  87. // When the user clicks on <span> (x), close the modal
  88. modalClose.onclick = function() {
  89. modal.remove();
  90. modalBackdrop.remove();
  91. document.body.style.overflow = "auto";
  92. }
  93.  
  94. // When the user clicks anywhere outside of the modal, close it
  95. modalBackdrop.onclick = function(event) {
  96. if (event.target == modalBackdrop) {
  97. modal.remove();
  98. modalBackdrop.remove();
  99. document.body.style.overflow = "auto";
  100. }
  101. }
  102. }
  103.  
  104. })();
Add Comment
Please, Sign In to add comment