// ==UserScript== // @name Fxxk GitHub's new UI // @name:zh-CN 拒绝 GitHub 新 UI // @namespace Aloxaf // @version 0.1 // @description Move repo information to the top. // @description:zh-CN 将 repo 信息移动至顶部 // @author Aloxaf // @match https://github.com/*/* // @grant GM_addStyle // @run-at document-start // @downloadURL none // ==/UserScript== // jshint esversion: 6 let content = $('.repository-content'); GM_addStyle(` .Box-header { padding: 8px 16px !important; } `); function $(e) { return document.querySelector(e); } function rename_node(node, name) { let ele = document.createElement(name); let old_attrs = node.attributes; let new_attrs = ele.attributes; for(let i = 0, len = old_attrs.length; i < len; i++) { new_attrs.setNamedItem(old_attrs.item(i).cloneNode()); } do { ele.appendChild(node.firstChild); } while (node.firstChild); node.parentNode.replaceChild(ele, node); return ele; } function xpath(s) { return document.evaluate(s, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; } function set_about() { console.log('setting about'); let about = xpath('//h2[text() = "About"]/following-sibling::p[1]'); about.className = "f4"; let url = xpath('//h2[text() = "About"]/following-sibling::div[1]/span/a'); if (url) { url.innerText = url.href; url.removeAttribute('class'); about.appendChild(url); } content.insertBefore(about, content.children[1]); } function set_topics() { console.log('setting topics'); let topics = xpath('//h3[text() = "Topics"]/following-sibling::div[1]'); topics.className = "repository-topics-container mt-2 mb-3 js-topics-list-container"; content.insertBefore(topics, content.children[2]); } function set_summary() { console.log('setting summary'); let overall_summary = document.createElement('div'); overall_summary.className = "overall-summary border-bottom-0 mb-0 rounded-bottom-0"; let summary = xpath('//h2[text() = "Git stats"]/following-sibling::ul[1]'); summary.className = "numbers-summary"; // Add contributors console.log('setting contributors'); let contributors = document.createElement('li'); let contri_nums = xpath('//a[contains(text(), "Contributors")]/span/text()'); // ?.textContent ?? 1; contri_nums = contri_nums ? contri_nums.textContent : 1; let contri_href = xpath('//a[contains(text(), "Contributors")]/@href'); contri_href = contri_href ? contri_href.value : `//${location.host}/${loaction.pathname}/graphs/contributors`; contributors.innerHTML = ` ${contri_nums} contributors `; summary.appendChild(contributors); // Add license console.log('setting license'); let license = document.createElement('li'); license.appendChild(xpath('//h3[text() = "License"]/following-sibling::div[1]/a')); license.children[0].className = "link-gray-dark no-underline d-inline-block"; summary.appendChild(license); overall_summary.appendChild(summary); content.insertBefore(overall_summary, content.children[3]); for (let li of summary.childNodes) { li.className = ''; } // Add languages progress console.log('setting languages'); let progress = xpath('//h2[text() = "Languages"]/following-sibling::div[1]/span'); let languages = document.createElement('div'); languages.className = 'repository-lang-stats'; languages.appendChild(rename_node(xpath('//h2[text() = "Languages"]/following-sibling::ul[1]'), 'ol')); languages.children[0].className = 'repository-lang-stats-numbers'; for (let li of languages.children[0].children) { li.removeAttribute('class'); li.children[0].removeAttribute('class'); let svg = li.children[0].children[0]; svg = rename_node(svg, "span"); svg.className = "color-block language-color"; svg.style.backgroundColor = svg.style.color; } let details = document.createElement('details'); details.className = "details-reset"; summary = document.createElement('summary'); summary.appendChild(progress); details.appendChild(summary); details.appendChild(languages); content.insertBefore(details, content.children[4]); } (function() { 'use strict'; let repo_content = $('.repository-content'); set_about(); set_topics(); set_summary(); // Hide new tab $('.file-navigation').className += " in-mid-page"; $('.repository-content > div > .flex-shrink-0:last-child').style.display = 'hidden'; let content = $('.repository-content > div > .flex-shrink-0'); content.className = content.className.replace('col-md-9', ''); })();