USO - add USOa button on userstyle page

Add a link to the copy of the current userstyle on uso.kkx.one

当前为 2023-02-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name USO - add USOa button on userstyle page
  3. // @namespace github.com/Procyon-b
  4. // @version 0.3.2
  5. // @description Add a link to the copy of the current userstyle on 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. var b=null;
  27.  
  28. function add() {
  29. var e;
  30. if (e=document.getElementById('USOa')) {
  31. // update url
  32. e.firstElementChild.href=aLink();
  33. return;
  34. }
  35.  
  36. b=document.querySelector('#top-buttons > .left') || document.querySelector('#buttons') || document.querySelector('div[class^="style-details_bottomRight_"]');
  37. const obs=new MutationObserver(function(muts){
  38. for (let mut of muts) {
  39. for (let n of mut.addedNodes) {
  40. b=n && n.querySelector && ( n.querySelector('#top-buttons > .left') || n.querySelector('#buttons') || n.querySelector('div[class^="style-details_bottomRight_"]') );
  41. if (b) {
  42. this.disconnect();
  43. setTimeout(addLink,0);
  44. return;
  45. }
  46. }
  47. }
  48. });
  49. if (b) addLink();
  50. else obs.observe(document.body, {attributes: false, subtree: true, childList: true });
  51. }
  52.  
  53. if (location.pathname.startsWith('/styles/')) add();
  54.  
  55. // old design - buttons can be removed
  56. window.addEventListener('resize', function(){
  57. setTimeout(add,0);
  58. })
  59.  
  60. function aLink() {
  61. return 'https://uso.kkx.one/style/'+location.pathname.split('/')[2];
  62. }
  63.  
  64. function addLink() {
  65. if (document.getElementById('USOa')) return;
  66. var L=aLink(),
  67. r=document.querySelector('div[class^="style-details_bottomRight_"]'),
  68. e=document.createElement('style');
  69. b.appendChild(e);
  70. 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}';
  71. if (r) {
  72. e.innerText+='div[class^="style-details_bottomRight_"] {display: flex; align-items: center;} #USOa {order: 9; margin-left: 0.5em; font-size: 13px;}';
  73. }
  74. e=document.createElement('div');
  75. b.appendChild(e);
  76. e.outerHTML='<div class="customize_style_button NOuninstall_stylish_style_button" id="USOa"><a href="'+L+'" class="oocustomize_button_text" target="_blank"><span>Install&nbsp;from<br>USO&nbsp;archive</span></a></div>';
  77. }
  78.  
  79. })();