您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
This script adds a button to sort tv show episodes by rating on IMDB.
// ==UserScript== // @name IMDb Sort Episodes by Rating // @description This script adds a button to sort tv show episodes by rating on IMDB. // @version 1 // @match *://www.imdb.com/title/tt* // @grant none // @namespace https://greasyfork.org/users/719286 // ==/UserScript== (function(){ window.addEventListener('load', () => { addButton('Sort by Rating', sortByRating) setInterval(checkButtonWasNotDeleted, 2000); }) function checkButtonWasNotDeleted() { if(!document.getElementById("Sort by Rating")){ addButton('Sort by Rating', sortByRating) } } function addButton(text, onclick, cssObj) { cssObj = cssObj || {"float":"right", "margin-right":"1em", "font-size": "0.50em", 'z-index': 3} let button = document.createElement('button'), btnStyle = button.style document.getElementById("episode_top").appendChild(button) button.innerHTML = text button.id = text button.onclick = onclick Object.keys(cssObj).forEach(key => btnStyle[key] = cssObj[key]) return button } function sortByRating() { parent = document.getElementsByClassName('list detail eplist')[0] for(var cardChild=parent.firstChild; cardChild!==null; cardChild=cardChild.nextSibling) { if(!cardChild.className){ continue; } cardChild.cardValue = getDescendantWithClass(cardChild,"ipl-rating-star__rating").textContent; console.log(cardChild); console.log(cardChild.cardValue); } [...parent.children] .sort((a,b)=>a.cardValue<b.cardValue?1:-1) .forEach(node=>parent.appendChild(node)); } function getDescendantWithClass(element, clName) { var children = element.childNodes; for (var i = 0; i < children.length; i++) { if (children[i].className && children[i].className.split(' ').indexOf(clName) >= 0) { return children[i]; } } for (var i = 0; i < children.length; i++) { var match = getDescendantWithClass(children[i], clName); if (match !== null) { return match; } } return null; } }())