基于下边这个佬的帖子修改
https://linux.do/t/topic/31420
新版本上线后选中ui样式有问题。
简单修改了下,要不看着不得劲儿。
效果:
下边是油猴代码:
// ==UserScript==
// @name Linux.do按帖子创建时间排序
// @namespace http://tampermonkey.net/
// @version 1.2
// @description 在 Linux.do 网页上修改链接和增加新链接
// @author 马克思
// @match https://linux.do/*
// @grant none
// @icon https://www.google.com/s2/favicons?sz=64&domain=linux.do
// ==/UserScript==
(function () {
'use strict';
var count = 0
function modifyNavigationBar() {
var navigationBar = document.querySelector('ul#navigation-bar');
if (navigationBar) {
var navigationItems = navigationBar.querySelectorAll('li');
navigationItems.forEach(function (item) {
var anchor = item.querySelector('a');
if (anchor && anchor.textContent.trim() === "最新") {
anchor.textContent = "最新回复";
var newestCreatedElement = document.createElement('li');
newestCreatedElement.title = "最新创建的帖子";
newestCreatedElement.id = "ember999";
item.insertAdjacentElement('afterend', newestCreatedElement);
console.log(location.href);
if (location.href.indexOf("order=created") !== -1) {
newestCreatedElement.className = "active latest_created ember-view nav-item_latest_created";
newestCreatedElement.innerHTML = '<a class="active" href="' + anchor.getAttribute('href') + '?order=created" >最新创建</a>';
anchor.className = ""
} else {
newestCreatedElement.className = "latest_created ember-view nav-item_latest_created";
newestCreatedElement.innerHTML = '<a href="' + anchor.getAttribute('href') + '?order=created" class="" >最新创建</a>';
}
return true;
}
});
}
}
// 使用 MutationObserver 来监视 DOM 变化
const observer = new MutationObserver((mutations) => {
for (let mutation of mutations) {
if (mutation.type === 'childList') {
const navBar = document.getElementById('navigation-bar');
if (navBar) {
modifyNavigationBar()
break;
}
}
}
});
// 开始观察 document.body 的变化
observer.observe(document.body, {childList: true, subtree: true});
// 如果页面已经加载完成,立即尝试添加新的导航项
if (document.readyState === 'complete' || document.readyState === 'interactive') {
console.log("complete")
modifyNavigationBar()
}
})();
