Guest User

popup unedited post

a guest
Aug 23rd, 2020
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. // ==UserScript==
  2. // @name popup unedited post
  3. // @namespace https://bitcointalk.org/
  4. // @version 0.1
  5. // @description popup unedited loyce (original post) 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:66vw;border-radius:5px;margin-left: -35px;}.modal-header{position:relative}.modal-header,.modal-body{padding:10px}.modal-header > h3{margin:0}.modal-close{cursor:pointer;padding:10px 20px;display:inline-block;position:absolute;top:0;right:0;opacity:0.8}.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}");
  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>The Original Post <a target="_blank" href="`+loyceURL+`">(unedited loyce backup)</a></h3><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 = '<img src="https://i.ibb.co/5j979m2/loading.gif" alt="" /> loading please wait ...';
  59.  
  60. if (this.readyState == 4 && this.status == 404)
  61. modalBody.innerHTML = "Sorry, there no unedited backup for this post.";
  62.  
  63. if (this.readyState == 4 && this.status == 200) {
  64. //modalBody.innerHTML = this.responseText;
  65.  
  66. /*from stackoverflow for test*/
  67. var doc = new DOMParser().parseFromString(this.responseText, 'text/html');
  68. var post = doc.querySelector('body').innerHTML;
  69.  
  70. modalBody.innerHTML = post;
  71. }
  72. };
  73.  
  74. xhttp.open("GET", loyceURL, true);
  75. xhttp.send();
  76.  
  77. }
  78.  
  79. load_unedited_post();
  80.  
  81. /** close the modal */
  82. // When the user clicks on <span> (x), close the modal
  83. modalClose.onclick = function() {
  84. modal.remove();
  85. modalBackdrop.remove();
  86. document.body.style.overflow = "auto";
  87. }
  88.  
  89. // When the user clicks anywhere outside of the modal, close it
  90. modalBackdrop.onclick = function(event) {
  91. if (event.target == modalBackdrop) {
  92. modal.remove();
  93. modalBackdrop.remove();
  94. document.body.style.overflow = "auto";
  95. }
  96. }
  97. }
  98.  
  99. })();
Add Comment
Please, Sign In to add comment