Guest User

popup unedited posts (loyce backup)

a guest
Aug 25th, 2020
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. // ==UserScript==
  2. // @name popup unedited posts (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{cursor:pointer;padding:10px 20px;display:inline-block;position:absolute;top:0;right:0;opacity:0.6}.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>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 = '<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. //modalBody.innerHTML = this.responseText;
  67.  
  68. /*from stackoverflow for test*/
  69. var doc = new DOMParser().parseFromString(this.responseText, 'text/html');
  70. var post = doc.querySelector('.post').innerHTML;
  71.  
  72. modalBody.innerHTML = '<div class="post">'+post+'</div>';
  73. }
  74. };
  75.  
  76. xhttp.open("GET", loyceURL, true);
  77. xhttp.send();
  78.  
  79. }
  80.  
  81. load_unedited_post();
  82.  
  83. /** close the modal */
  84. // When the user clicks on <span> (x), close the modal
  85. modalClose.onclick = function() {
  86. modal.remove();
  87. modalBackdrop.remove();
  88. document.body.style.overflow = "auto";
  89. }
  90.  
  91. // When the user clicks anywhere outside of the modal, close it
  92. modalBackdrop.onclick = function(event) {
  93. if (event.target == modalBackdrop) {
  94. modal.remove();
  95. modalBackdrop.remove();
  96. document.body.style.overflow = "auto";
  97. }
  98. }
  99. }
  100.  
  101. })();
Add Comment
Please, Sign In to add comment