USO - add USOa button on userstyle page

Add a link on userstyles.org to the copy of the current userstyle on "USO archive" (uso.kkx.one)

目前為 2023-03-06 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name USO - add USOa button on userstyle page
  3. // @namespace github.com/Procyon-b
  4. // @version 0.3.4
  5. // @description Add a link on userstyles.org to the copy of the current userstyle on "USO archive" (uso.kkx.one)
  6. // @author Achernar
  7. // @match https://userstyles.org/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. "use strict";
  13.  
  14. var newL=document.querySelector('#__next');
  15. var pushState=history.pushState;
  16.  
  17. if (newL) {
  18. history.pushState=function(){
  19. pushState.apply(history, arguments);
  20. if (location.pathname.startsWith('/styles/')) {
  21. setTimeout(add, 0);
  22. }
  23. }
  24. }
  25.  
  26. const obs=new MutationObserver(function(muts){
  27. for (let mut of muts) {
  28. for (let n of mut.addedNodes) {
  29. b=n && n.querySelector && ( n.querySelector('#top-buttons > .left') || n.querySelector('#buttons') || n.querySelector('div[class^="style-details_bottomRight_"]') );
  30. if (b) {
  31. if (!newL) this.disconnect();
  32. setTimeout(addLink,0);
  33. return;
  34. }
  35. }
  36. }
  37. });
  38. obs.observe(document.body, {attributes: false, subtree: true, childList: true });
  39.  
  40. var b=null;
  41.  
  42. function add() {
  43. var e;
  44. if (e=document.getElementById('USOa')) {
  45. // update url
  46. e.firstElementChild.href=aLink();
  47. return;
  48. }
  49.  
  50. b=document.querySelector('#top-buttons > .left') || document.querySelector('#buttons') || document.querySelector('div[class^="style-details_bottomRight_"]');
  51.  
  52. if (b) addLink();
  53. }
  54.  
  55. if (location.pathname.startsWith('/styles/')) add();
  56.  
  57. // old design - buttons can be removed
  58. window.addEventListener('resize', function(){
  59. setTimeout(add,0);
  60. })
  61.  
  62. function aLink() {
  63. return 'https://uso.kkx.one/style/'+location.pathname.split('/')[2];
  64. }
  65.  
  66. function addLink() {
  67. if (document.getElementById('USOa')) return;
  68. var L=aLink(),
  69. r=document.querySelector('div[class^="style-details_bottomRight_"]'),
  70. e=document.createElement('style');
  71. b.appendChild(e);
  72. e.innerText='.upgradeButton {margin-right: 11px;} #USOa {background: #39c739; color: white; text-align: center; order: 9; width: unset; padding: 0 1em; border-radius: 24px; border: none;} #USOa a {color: inherit; line-height: 1.3em} #style-top-upvotes-wrapper {white-space: nowrap;} #style-top-upvotes-wrapper.can-vote {position: relative;} #style-top-upvotes-wrapper.can-vote:hover .button-wrapper {display: flex !important; visibility: hidden;} #style-top-upvotes-wrapper.can-vote .button-wrapper ~ img {position: absolute !important; right: 0;}';
  73. if (r) {
  74. e.innerText+='div[class^="style-details_bottomRight_"] {display: flex; align-items: center;} #USOa {order: 9; margin-left: 0.5em; font-size: 13px;}';
  75. }
  76. e=document.createElement('div');
  77. b.appendChild(e);
  78. e.outerHTML='<div class="customize_style_button" id="USOa"><a href="'+L+'" target="_blank"><span>Install&nbsp;from<br>USO&nbsp;archive</span></a></div>';
  79. }
  80.  
  81. })();