Advertisement
Nik333

Realmeye wiki scripts

Nov 24th, 2021
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Realmeye Shortcuts
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @include https://www.realmeye.com/*
  8. // @include https://imgur.com/a/*
  9. // @icon https://www.realmeye.com/s/ew/img/favicon.ico
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. let heldShift = false;
  14. let cancelShift = undefined;
  15.  
  16. (function() {
  17. document.addEventListener('keydown', (e) => keyDown(e.key));
  18. document.addEventListener('keyup', (e) => keyUp(e.key));
  19.  
  20. const targetNode = document.getElementById('some-id');
  21.  
  22. // Options for the observer (which mutations to observe)
  23. const config = { attributes: true, childList: true, subtree: true };
  24.  
  25. // Callback function to execute when mutations are observed
  26. const callback = function(mutationsList, observer) {
  27. // Use traditional 'for loops' for IE 11
  28. for(const mutation of mutationsList) {
  29. if (mutation.type === 'childList') {
  30. if (mutation.addedNodes && mutation.addedNodes.length > 0) {
  31. for (let img of mutation.addedNodes[0].querySelectorAll(".PostContent-imageWrapper-rounded img, .imageContainer img.image-placeholder")) {
  32. img.addEventListener('click', event => {
  33. if (!heldShift) return;
  34. if (img.src.match(/\.com\/(.*)\.png/))
  35. navigator.clipboard.writeText(img.src.match(/\.com\/(.*)\.png/)[1]);
  36. if (img.src.match(/\.com\/(.*)_d\.webp/))
  37. navigator.clipboard.writeText(img.src.match(/\.com\/(.*)_d\.webp/)[1]);
  38. });
  39. }
  40. }
  41. }
  42. }
  43. };
  44.  
  45. if (document.location.href.match('realmeye.com/wiki/')) {
  46. const svgEdit = `<svg width="22" aria-hidden="true" focusable="false" data-prefix="far" data-icon="edit" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" class="svg-inline--fa fa-edit fa-w-18 fa-lg"><path fill="currentColor" d="M402.3 344.9l32-32c5-5 13.7-1.5 13.7 5.7V464c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V112c0-26.5 21.5-48 48-48h273.5c7.1 0 10.7 8.6 5.7 13.7l-32 32c-1.5 1.5-3.5 2.3-5.7 2.3H48v352h352V350.5c0-2.1.8-4.1 2.3-5.6zm156.6-201.8L296.3 405.7l-90.4 10c-26.2 2.9-48.5-19.2-45.6-45.6l10-90.4L432.9 17.1c22.9-22.9 59.9-22.9 82.7 0l43.2 43.2c22.9 22.9 22.9 60 .1 82.8zM460.1 174L402 115.9 216.2 301.8l-7.3 65.3 65.3-7.3L460.1 174zm64.8-79.7l-43.2-43.2c-4.1-4.1-10.8-4.1-14.8 0L436 82l58.1 58.1 30.9-30.9c4-4.2 4-10.8-.1-14.9z" class=""></path></svg>`
  47. const newLink = document.location.href.replace('/wiki/', '/edit-wiki-page/');
  48. document.getElementsByTagName('h1')[0].innerHTML += ' <a href="' + newLink + '">' + svgEdit + '</a>';
  49. }
  50.  
  51. // Create an observer instance linked to the callback function
  52. const observer = new MutationObserver(callback);
  53.  
  54. // Start observing the target node for configured mutations
  55. observer.observe(document.body, config);
  56.  
  57. function keyUp(key) {
  58. switch (key) {
  59. case 'Shift':
  60. clearTimeout(cancelShift);
  61. heldShift = false;
  62. break;
  63. }
  64. }
  65. function keyDown(key) {
  66. switch (key) {
  67. case 'Shift':
  68. clearTimeout(cancelShift);
  69. cancelShift = setTimeout(
  70. () => heldShift = false, 2000
  71. );
  72. heldShift = true;
  73. break;
  74. case 'P':
  75. if (!heldShift) break;
  76. navigator.clipboard.writeText(document.querySelector('img.img-responsive').src.match(/\.com\/(.*)\.png/)[1]);
  77. break;
  78. }
  79. }
  80. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement