Greasy Fork is available in English.
在创意工坊中注入一个MOD下载按钮,用于下载MOD,API来源:https://t.vvwall.com
当前为
// ==UserScript==
// @name Steam创意工坊饥荒mod下载工具
// @namespace http://greasyfork.icu/users/3128
// @version 0.5
// @description 在创意工坊中注入一个MOD下载按钮,用于下载MOD,API来源:https://t.vvwall.com
// @author You
// @include https://steamcommunity.com/sharedfiles/filedetails/*
// @match https://t.vvwall.com/*
// @connect 5.5w.pw
// @grant GM_setClipboard
// @grant GM_addStyle
// @grant GM_download
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
'use strict';
let webHost=location.host;
if(webHost=='steamcommunity.com') {
let down_A=document.createElement('a');
//down_A.href="https://t.vvwall.com/#"+publishedfileid;
down_A.id="download_Mod";
down_A.target='_blank';
down_A.textContent='下载 MOD';
let down_span=document.createElement('span');
down_span.className='general_btn share tooltip';
down_span.appendChild(down_A);
document.querySelector('#ItemControls').appendChild(down_span);
document.querySelector('#download_Mod').addEventListener('click', function(){
GM_xmlhttpRequest({
url:'https://5.5w.pw/api?mid='+publishedfileid,
method: 'get',
responseType : 'json',
onload: function(e){
console.log(e);
let data=e.response, downloadTitle="[workshop-"+publishedfileid+"]"+data.title+".zip";
GM_download({
url: data.url,
name: downloadTitle,
saveAs : true,
});
},
onerror: function(e){
console.error('error', e);
}
});
});
/*
let down_A=$('<a>').text('下载MOD'),
downBtn=$('<span class="general_btn report tooltip" data-tooltip-text="下载MOD">').append(down_A);
*/
} else if(webHost=='t.vvwall.com') {
GM_addStyle(`
input[name="mid"]{
padding: 0 10px;
}
`);
$('button.starts').click(function(){
addMObserver('#des', function(){
console.log($('code#des').text());
$('code#des').html(markdown.toHTML($('code#des').text()));
});
});
let workshop_A=$('<a id="workshop">').text('创意工坊');
let dlbtn=$('#dlbtn').removeAttr('onclick target').click(function(e){
let inputText=$('input[name="mid"]').val().trim(),
id=getUrlParam('id', inputText, inputText),
modTitle=$('#modtitle').text().trim(),
downloadTitle="[workshop-"+id+"]"+modTitle+".zip";
workshop_A.attr({'href':'https://steamcommunity.com/sharedfiles/filedetails/?id='+id});
GM_download({
url: e.href,
name: downloadTitle,
saveAs : true,
});
e.preventDefault(); //阻止默认动作
e.stopPropagation(); //阻止冒泡
});
$('.downloadbox').prepend(dlbtn);
dlbtn.after(workshop_A);
}
if(location.hash) {
$('input[name="mid"]').val(location.hash.replace('#',''));
$('button.starts').click();
}
// Your code here...
function addMObserver(selector, callback, Kill, option) {
var watch = document.querySelector(selector);
if (!watch) {
return;
}
console.warn('watch:', watch, selector);
var observer = new MutationObserver(function(mutations){
console.log('mutations:', mutations);
var nodeAdded = mutations.some(function(x){
console.log(x);
return x.addedNodes.length > 0;
});
console.log(nodeAdded);
if (nodeAdded) {
console.log(mutations, observer);
callback(mutations, observer);
if(Kill) {
console.log('停止'+selector+'的监控');
observer.disconnect();
}
}
});
observer.observe(watch, option||{childList: true, subtree: true});//
}
function getUrlParam(name, url, option, newVal) {//筛选参数,url 参数为数字时
var search = url ? url.replace(/^.+\?/,'') : location.search;
//网址传递的参数提取,如果传入了url参数则使用传入的参数,否则使用当前页面的网址参数
var reg = new RegExp("(?:^|&)(" + name + ")=([^&]*)(?:&|$)", "i"); //正则筛选参数
var str = search.replace(/^\?/,'').match(reg);
console.log(str, option);
if (str !== null) {
switch(option) {
case 0:
return unescape(str[0]); //所筛选的完整参数串
case 1:
return unescape(str[1]); //所筛选的参数名
case 2:
return unescape(str[2]); //所筛选的参数值
case 'new':
return url.replace(str[1]+'='+str[2], str[1]+'='+newVal);
default:
return unescape(str[2]); //默认返回参数值
}
} else if(!str && option) {
return option;
} else {
return null;
}
}
})();