Github1s

在 Github 网站顶部显示 Github1s 按钮,Github1s 是一个利用 VsCode Online 浏览代码的项目

  1. // ==UserScript==
  2. // @name Github1s
  3. // @icon https://github.githubassets.com/pinned-octocat.svg
  4. // @version 1.0.2
  5. // @description 在 Github 网站顶部显示 Github1s 按钮,Github1s 是一个利用 VsCode Online 浏览代码的项目
  6. // @author zw95
  7. // @originAuthor 桔子
  8. // @match https://github.com/*
  9. // @grant GM_addStyle
  10. // @run-at document-end
  11. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.slim.min.js
  12. // @require https://gf.qytechs.cn/scripts/475259-elementgetter-alone/code/ElementGetter_Alone.js?version=1250106
  13. // @namespace https://gf.qytechs.cn/users/991143
  14. // @scriptHomePage https://gf.qytechs.cn/scripts/486673
  15. // ==/UserScript==
  16.  
  17. var themeMode;
  18. (function () {
  19. "use strict";
  20. init();
  21. style();
  22. work();
  23. })();
  24.  
  25. function init(){
  26. themeMode = document.querySelector("html")?.getAttribute('data-color-mode') || 'light';
  27. }
  28. /**
  29. * 创建 Github1s 按钮
  30. */
  31. function work() {
  32. // 首页按钮
  33. elmGetter.get('.pagehead-actions.flex-shrink-0.d-none.d-md-inline').then((node) => {
  34. const github1sUrl = `https://github1s.com${location.pathname}`;
  35. const element = '<li id="github1sProjectButton"> <a target="_blank" class="btn btn-sm" href="' + github1sUrl + '"> <svg t="1613127032045" class="icon octicon octicon-heart text-pink" viewBox="0 0 1025 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2120" width="16.015625" height="16" xmlns:xlink="http://www.w3.org/1999/xlink"> <path d="M512.032 831.904c-19.168 0-38.304-9.92-58.144-29.76-7.808-7.808-7.808-20.48 0-28.288s20.48-7.808 28.288 0C494.368 786.08 504.16 792 512.032 792s17.664-5.92 29.856-18.144c7.808-7.808 20.48-7.808 28.288 0s7.808 20.48 0 28.288c-19.84 19.84-38.976 29.76-58.144 29.76z m-512-306.4c0 49.888 4.256 95.136 12.8 135.68s20.544 75.744 36 105.536 35.008 55.904 58.656 78.336 49.344 40.928 77.056 55.456c27.744 14.528 59.456 26.304 95.2 35.264S351.84 951.04 388.8 954.624 466.496 960 510.944 960c44.448 0 85.248-1.792 122.4-5.376s73.6-9.856 109.344-18.848c35.744-8.96 67.552-20.736 95.456-35.264s53.792-33.024 77.6-55.456c23.808-22.432 43.456-48.544 58.944-78.336s27.552-64.96 36.256-105.536c8.704-40.576 13.056-85.792 13.056-135.68 0-89.376-27.744-166.368-83.2-230.976 3.2-8.608 5.952-18.496 8.256-29.6s4.544-26.816 6.656-47.104c2.144-20.288 1.344-43.712-2.4-70.272S942.56 93.888 932.256 66.24l-8-1.632c-5.344-1.088-14.048-0.704-26.144 1.088s-26.208 5.024-42.4 9.696-37.056 13.92-62.656 27.744-52.608 31.328-81.056 52.512c-48.352-14.72-115.008-30.112-200-30.112s-151.808 15.392-200.544 30.112c-28.448-21.184-55.552-38.592-81.344-52.224s-46.4-22.976-61.856-28c-15.456-5.024-29.792-8.256-42.944-9.696s-21.6-1.888-25.344-1.344c-3.744 0.544-6.496 1.152-8.256 1.888-10.304 27.648-17.408 54.752-21.344 81.312s-4.8 49.888-2.656 69.984c2.144 20.096 4.448 35.904 6.944 47.392S80 286.304 83.2 294.56C27.744 358.816 0 435.808 0 525.536z m136.544 113.888c0-58.016 21.344-110.624 64-157.856 12.8-14.4 27.648-25.312 44.544-32.704s36.096-11.616 57.6-12.608 42.048-0.8 61.6 0.608 43.744 3.296 72.544 5.696 53.696 3.616 74.656 3.616c20.96 0 45.856-1.184 74.656-3.616s52.992-4.288 72.544-5.696c19.552-1.408 40.096-1.6 61.6-0.608s40.8 5.216 57.856 12.608c17.056 7.392 32 18.304 44.8 32.704 42.656 47.232 64 99.84 64 157.856 0 34.016-3.552 64.32-10.656 90.944s-16.096 48.928-26.944 66.912c-10.848 18.016-26.048 33.216-45.6 45.632s-38.496 22.016-56.8 28.8c-18.304 6.784-41.952 12.096-70.944 15.904s-54.944 6.112-77.856 6.912c-22.944 0.8-51.808 1.216-86.656 1.216s-63.648-0.416-86.4-1.216c-22.752-0.8-48.608-3.104-77.6-6.912s-52.608-9.12-70.944-15.904c-18.304-6.816-37.248-16.416-56.8-28.8s-34.752-27.616-45.6-45.632c-10.848-18.016-19.84-40.32-26.944-66.912s-10.656-56.928-10.656-90.944zM256.032 608c0-53.024 28.64-96 64-96s64 42.976 64 96-28.64 96-64 96-64-42.976-64-96z m384 0c0-53.024 28.64-96 64-96s64 42.976 64 96-28.64 96-64 96-64-42.976-64-96z" p-id="2121" fill="var(--color-codemirror-text)"></path> </svg></a> </li>';
  36.  
  37. node.insertAdjacentHTML('afterBegin', element);
  38. });
  39.  
  40. // 单文件按钮
  41. // elmGetter.get('.react-blob-header-edit-and-raw-actions > div:nth-child(1)').then((fileEditbutton) => {
  42. elmGetter.each('.react-blob-header-edit-and-raw-actions', document,(fileEditbutton) => {
  43. const parentNode = fileEditbutton.parentNode;
  44.  
  45. console.log(1)
  46. const fileButton = document.createElement('button');
  47. fileButton.className='btn btn-sm';
  48. fileButton.innerHTML = `<svg t="1613127032045" class="icon octicon octicon-heart text-pink" viewBox="0 0 1025 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2120" width="16.015625" height="16" xmlns:xlink="http://www.w3.org/1999/xlink"> <path d="M512.032 831.904c-19.168 0-38.304-9.92-58.144-29.76-7.808-7.808-7.808-20.48 0-28.288s20.48-7.808 28.288 0C494.368 786.08 504.16 792 512.032 792s17.664-5.92 29.856-18.144c7.808-7.808 20.48-7.808 28.288 0s7.808 20.48 0 28.288c-19.84 19.84-38.976 29.76-58.144 29.76z m-512-306.4c0 49.888 4.256 95.136 12.8 135.68s20.544 75.744 36 105.536 35.008 55.904 58.656 78.336 49.344 40.928 77.056 55.456c27.744 14.528 59.456 26.304 95.2 35.264S351.84 951.04 388.8 954.624 466.496 960 510.944 960c44.448 0 85.248-1.792 122.4-5.376s73.6-9.856 109.344-18.848c35.744-8.96 67.552-20.736 95.456-35.264s53.792-33.024 77.6-55.456c23.808-22.432 43.456-48.544 58.944-78.336s27.552-64.96 36.256-105.536c8.704-40.576 13.056-85.792 13.056-135.68 0-89.376-27.744-166.368-83.2-230.976 3.2-8.608 5.952-18.496 8.256-29.6s4.544-26.816 6.656-47.104c2.144-20.288 1.344-43.712-2.4-70.272S942.56 93.888 932.256 66.24l-8-1.632c-5.344-1.088-14.048-0.704-26.144 1.088s-26.208 5.024-42.4 9.696-37.056 13.92-62.656 27.744-52.608 31.328-81.056 52.512c-48.352-14.72-115.008-30.112-200-30.112s-151.808 15.392-200.544 30.112c-28.448-21.184-55.552-38.592-81.344-52.224s-46.4-22.976-61.856-28c-15.456-5.024-29.792-8.256-42.944-9.696s-21.6-1.888-25.344-1.344c-3.744 0.544-6.496 1.152-8.256 1.888-10.304 27.648-17.408 54.752-21.344 81.312s-4.8 49.888-2.656 69.984c2.144 20.096 4.448 35.904 6.944 47.392S80 286.304 83.2 294.56C27.744 358.816 0 435.808 0 525.536z m136.544 113.888c0-58.016 21.344-110.624 64-157.856 12.8-14.4 27.648-25.312 44.544-32.704s36.096-11.616 57.6-12.608 42.048-0.8 61.6 0.608 43.744 3.296 72.544 5.696 53.696 3.616 74.656 3.616c20.96 0 45.856-1.184 74.656-3.616s52.992-4.288 72.544-5.696c19.552-1.408 40.096-1.6 61.6-0.608s40.8 5.216 57.856 12.608c17.056 7.392 32 18.304 44.8 32.704 42.656 47.232 64 99.84 64 157.856 0 34.016-3.552 64.32-10.656 90.944s-16.096 48.928-26.944 66.912c-10.848 18.016-26.048 33.216-45.6 45.632s-38.496 22.016-56.8 28.8c-18.304 6.784-41.952 12.096-70.944 15.904s-54.944 6.112-77.856 6.912c-22.944 0.8-51.808 1.216-86.656 1.216s-63.648-0.416-86.4-1.216c-22.752-0.8-48.608-3.104-77.6-6.912s-52.608-9.12-70.944-15.904c-18.304-6.816-37.248-16.416-56.8-28.8s-34.752-27.616-45.6-45.632c-10.848-18.016-19.84-40.32-26.944-66.912s-10.656-56.928-10.656-90.944zM256.032 608c0-53.024 28.64-96 64-96s64 42.976 64 96-28.64 96-64 96-64-42.976-64-96z m384 0c0-53.024 28.64-96 64-96s64 42.976 64 96-28.64 96-64 96-64-42.976-64-96z" p-id="2121" fill="var(--color-codemirror-text)"></path> </svg>`;
  49.  
  50. // RAW URL 按钮
  51. elmGetter.get('button[aria-label="Copy raw content"]').then((rawFileButton) => {
  52. // elmGetter.each('button[aria-label="Copy raw content"]', document,(rawFileButton) => {
  53.  
  54. var copyRawURLBtn = rawFileButton.cloneNode(true);
  55. copyRawURLBtn.removeAttribute('data-component');
  56. copyRawURLBtn.removeAttribute('data-testid');
  57. copyRawURLBtn.attributes['aria-label'] = 'Copy raw URL';
  58. copyRawURLBtn.attributes['id'] = 'copyRawURLBtn';
  59. copyRawURLBtn.title = '复制Raw URL';
  60. copyRawURLBtn.className = 'btn btn-sm'
  61. copyRawURLBtn.innerHTML = '<svg t="1715571239682" class="octicon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8619" width="16" height="16"><path d="M578.133 675.627c-3.306-3.307-8.746-3.307-12.053 0L442.133 799.573c-57.386 57.387-154.24 63.467-217.6 0-63.466-63.466-57.386-160.213 0-217.6L348.48 458.027c3.307-3.307 3.307-8.747 0-12.054l-42.453-42.453c-3.307-3.307-8.747-3.307-12.054 0L170.027 527.467c-90.24 90.24-90.24 236.266 0 326.4s236.266 90.24 326.4 0L620.373 729.92c3.307-3.307 3.307-8.747 0-12.053l-42.24-42.24z m275.84-505.6c-90.24-90.24-236.266-90.24-326.4 0L403.52 293.973c-3.307 3.307-3.307 8.747 0 12.054l42.347 42.346c3.306 3.307 8.746 3.307 12.053 0l123.947-123.946c57.386-57.387 154.24-63.467 217.6 0 63.466 63.466 57.386 160.213 0 217.6L675.52 565.973c-3.307 3.307-3.307 8.747 0 12.054l42.453 42.453c3.307 3.307 8.747 3.307 12.054 0l123.946-123.947c90.134-90.24 90.134-236.266 0-326.506z" p-id="8620"></path><path d="M616.64 362.987c-3.307-3.307-8.747-3.307-12.053 0l-241.6 241.493c-3.307 3.307-3.307 8.747 0 12.053l42.24 42.24c3.306 3.307 8.746 3.307 12.053 0L658.773 417.28c3.307-3.307 3.307-8.747 0-12.053l-42.133-42.24z" p-id="8621"></path></svg>'
  62. copyRawURLBtn.addEventListener("click", function() {
  63. // 复制固定文字到剪贴板
  64. var textArea = document.createElement('textarea');
  65. const fileRawPath = `${location.pathname}`.replace(/^\/((?:\w|-)+)\/((?:\w|-)+)\/blob\//, '/$1/$2/')
  66. const fileRawURL = `https://raw.githubusercontent.com${fileRawPath}`
  67. textArea.value = fileRawURL;
  68. document.body.appendChild(textArea);
  69. textArea.select();
  70. try {
  71. var successful = document.execCommand('copy');
  72. var msg = successful ? '成功复制' : '复制失败';
  73. console.log(msg);
  74. } catch (err) {
  75. console.error('无法复制文本: ', err);
  76. }
  77. document.body.removeChild(textArea);
  78. const x = copyRawURLBtn.getBoundingClientRect().left - fileButton.clientWidth;
  79. const y = copyRawURLBtn.getBoundingClientRect().top - copyRawURLBtn.clientHeight -8;
  80. showTip('已复制!',x,y);
  81. setTimeout(()=>{
  82. cleanTip();
  83. },2000);
  84. });
  85.  
  86. copyRawURLBtn.addEventListener("mouseover", function() {
  87. const x = copyRawURLBtn.getBoundingClientRect().left - fileButton.clientWidth;
  88. const y = copyRawURLBtn.getBoundingClientRect().top - copyRawURLBtn.clientHeight -8;
  89. showTip('复制Raw URL',x,y);
  90. });
  91.  
  92. copyRawURLBtn.addEventListener("mouseout", function() {
  93. cleanTip();
  94. });
  95.  
  96. // 添加复制RAW URL 按钮
  97. if(parentNode.firstChild){
  98. parentNode.insertBefore(copyRawURLBtn, parentNode.firstChild);
  99. } else {
  100. parentNode.appendChild(copyRawURLBtn);
  101. }
  102.  
  103. });
  104. fileButton.addEventListener("click", function() {
  105. const github1sUrl = `https://github1s.com${location.pathname}`;
  106. window.open(github1sUrl, '_blank');
  107. });
  108. fileButton.addEventListener("mouseover", function() {
  109. const x = fileButton.getBoundingClientRect().left - fileButton.clientWidth;
  110. const y = fileButton.getBoundingClientRect().top - fileButton.clientHeight -8;
  111. showTip('在Github1s中打开',x,y);
  112. });
  113.  
  114. fileButton.addEventListener("mouseout", function() {
  115. cleanTip();
  116. });
  117. // 添加单文件按钮
  118. parentNode.insertBefore(fileButton,parentNode.firstChild);
  119.  
  120. });
  121.  
  122. }
  123.  
  124. function showTip(msg,x,y,color){
  125. var tipDiv = document.querySelector("#__primerPortalRoot__");
  126. var toopTip = document.querySelector('#tooltip');
  127. var tipChildHtml = `<div style="position: relative; z-index: 1;"><span role="tooltip" id="raw-copy-message-tooltip" aria-live="assertive" class="" style="position: absolute; left: ${x}px; top: ${y}px; display:inline-block;padding:.5em .75em;font:11px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI','Noto Sans',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji';color:${color?color:'var(--fgColor-onEmphasis, var(--color-fg-on-emphasis, #ffffff))'};text-align:center;letter-spacing:normal;overflow-wrap:break-word;white-space:pre;pointer-events:none;background:${'var(--bgColor-emphasis,var(--color-neutral-emphasis-plus, #6e7681))'};border-radius:6px">${msg}</span></div>`;
  128. if(tipDiv){
  129. !toopTip && (tipDiv.innerHTML = tipChildHtml);
  130. }else{
  131. tipDiv = document.createElement('div')
  132. tipDiv.id = '__primerPortalRoot__';
  133. tipDiv.style.position = 'absolute';
  134. tipDiv.style.left = '0px';
  135. tipDiv.style.top = '0px';
  136. !toopTip && (tipDiv.innerHTML = tipChildHtml)
  137. document.body.appendChild(tipDiv);
  138. console.log('显示失败,没找到!');
  139. }
  140. }
  141.  
  142. function cleanTip(){
  143. const tipDiv = document.querySelector("#__primerPortalRoot__");
  144. if(tipDiv){
  145. tipDiv.innerHTML = ``;
  146. }else{
  147. console.log('隐藏失败,没找到!');
  148. }
  149. }
  150. function style(){
  151. GM_addStyle(`
  152. .btn-sm {
  153. padding: 3px 8px;
  154. font-size: 12px;
  155. line-height: 20px;
  156. }
  157. `);
  158. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址