Barter.vg Wishlist Match Enhancer

Removes untradable items (0 tradable), and sort list in descending order by number of traders

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Barter.vg Wishlist Match Enhancer
// @description  Removes untradable items (0 tradable), and sort list in descending order by number of traders
// @namespace    http://tampermonkey.net/
// @version      0.1
// @author       mcbyte
// @match        https://barter.vg/u/*/w/m/
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @runat        document-end
// @grant        none
// ==/UserScript==

this.$ = this.jQuery = jQuery.noConflict(true);

(function() {
    'use strict';

    $('#wishGame > option').each(function() {
		if (this.text.endsWith('(0)')) {
			$(this).remove();
		}
    });

	// sort select menu
	$('#wishGame > option').each(function() {
		var tradeCountObj = this.text.match(/\((\d+)\)/);
		if (tradeCountObj != null) {
			var tradeCount = tradeCountObj[1];
			$(this).attr('dataSort', tradeCount);
			console.log(this.text + ' is traded by this many people: ' + tradeCount);
		}
    });

	var selectList = $('#wishGame option');

	selectList.sort(function(a,b){
		var aVal = $(a).attr('dataSort');
		var bVal = $(b).attr('dataSort');
		if (aVal != bVal) {
			return  bVal - aVal;
		} else {
			return ($(a).text() > $(b).text() ? 1 : -1);
		}
	});
	console.log(selectList);
	$('#wishGame').empty().append(selectList);
	$('#wishGame').val('0');
	$('#wishGame option:first').text('[ any game on wishlist ] (Enhanced+)');

})();