/* eslint-disable no-multi-spaces */
// ==UserScript==
// @name Greasyfork 快捷编辑收藏
// @name:zh-CN Greasyfork 快捷编辑收藏
// @name:zh-TW Greasyfork 快捷編輯收藏
// @name:en Greasyfork script-set-edit button
// @name:en-US Greasyfork script-set-edit button
// @namespace Greasyfork-Favorite
// @version 0.1.5
// @description 在GF脚本页添加快速打开收藏集编辑页面功能
// @description:zh-CN 在GF脚本页添加快速打开收藏集编辑页面功能
// @description:zh-TW 在GF腳本頁添加快速打開收藏集編輯頁面功能
// @description:en Add open script-set-edit-page button in GF script page
// @description:en-US Add open script-set-edit-page button in GF script page
// @author PY-DNG
// @license GPL-3
// @match http*://greasyfork.org/*
// @match http*://sleazyfork.org/*
// @include http*://greasyfork.org/*
// @include http*://sleazyfork.org/*
// @icon https://api.iowen.cn/favicon/get.php?url=greasyfork.org
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @downloadURL none
// ==/UserScript==
(function __MAIN__() {
'use strict';
// Polyfills
const script_name = '新的用户脚本';
const script_version = '0.1';
const NMonkey_Info = {
GM_info: {
script: {
name: script_name,
author: 'PY-DNG',
version: script_version
}
},
mainFunc: __MAIN__
};
const NMonkey_Ready = NMonkey(NMonkey_Info);
if (!NMonkey_Ready) {return false;}
polyfill_replaceAll();
// Arguments: level=LogLevel.Info, logContent, asObject=false
// Needs one call "DoLog();" to get it initialized before using it!
function DoLog() {
// Get window
const win = (typeof(unsafeWindow) === 'object' && unsafeWindow !== null) ? unsafeWindow : window ;
// Global log levels set
win.LogLevel = {
None: 0,
Error: 1,
Success: 2,
Warning: 3,
Info: 4,
}
win.LogLevelMap = {};
win.LogLevelMap[LogLevel.None] = {prefix: '' , color: 'color:#ffffff'}
win.LogLevelMap[LogLevel.Error] = {prefix: '[Error]' , color: 'color:#ff0000'}
win.LogLevelMap[LogLevel.Success] = {prefix: '[Success]' , color: 'color:#00aa00'}
win.LogLevelMap[LogLevel.Warning] = {prefix: '[Warning]' , color: 'color:#ffa500'}
win.LogLevelMap[LogLevel.Info] = {prefix: '[Info]' , color: 'color:#888888'}
win.LogLevelMap[LogLevel.Elements] = {prefix: '[Elements]', color: 'color:#000000'}
// Current log level
DoLog.logLevel = win.isPY_DNG ? LogLevel.Info : LogLevel.Warning; // Info Warning Success Error
// Log counter
DoLog.logCount === undefined && (DoLog.logCount = 0);
// Get args
let level, logContent, asObject;
switch (arguments.length) {
case 1:
level = LogLevel.Info;
logContent = arguments[0];
asObject = false;
break;
case 2:
level = arguments[0];
logContent = arguments[1];
asObject = false;
break;
case 3:
level = arguments[0];
logContent = arguments[1];
asObject = arguments[2];
break;
default:
level = LogLevel.Info;
logContent = 'DoLog initialized.';
asObject = false;
break;
}
// Log when log level permits
if (level <= DoLog.logLevel) {
let msg = '%c' + LogLevelMap[level].prefix;
let subst = LogLevelMap[level].color;
if (asObject) {
msg += ' %o';
} else {
switch(typeof(logContent)) {
case 'string': msg += ' %s'; break;
case 'number': msg += ' %d'; break;
case 'object': msg += ' %o'; break;
}
}
if (++DoLog.logCount > 512) {
console.clear();
DoLog.logCount = 0;
}
console.log(msg, subst, logContent);
}
}
DoLog();
const CONST = {
Text: {
'zh-CN': {
FavEdit: '收藏集:',
Add: '加入此集',
Edit: '手动编辑',
CopySID: '复制脚本ID',
Working: ['正在添加...', '就快好了...'],
Error: {
Unknown: '未知错误'
}
},
'zh-TW': {
FavEdit: '收藏集:',
Add: '加入此集',
Edit: '手動編輯',
CopySID: '複製腳本ID',
Working: ['正在添加...', '就快好了...'],
Error: {
Unknown: '未知錯誤'
}
},
'en': {
FavEdit: 'Add to/Remove from favorite list: ',
Add: 'Add',
Edit: 'Edit Manually',
CopySID: 'Copy-Script-ID',
Working: ['Working...', 'Just a moment...'],
Error: {
Unknown: 'Unknown Error'
}
},
'default': {
FavEdit: 'Add to/Remove from favorite list: ',
Add: 'Add',
Edit: 'Edit Manually',
CopySID: 'Copy-Script-ID',
Working: ['Working...', 'Just a moment...'],
Error: {
Unknown: 'Unknown Error'
}
},
}
}
// Get i18n code
let i18n = navigator.language;
if (!Object.keys(CONST.Text).includes(i18n)) {i18n = 'default';}
main()
function main() {
const HOST = getHost();
const API = getAPI();
// Common actions
commons();
// API-based actions
switch(API[1]) {
case "scripts":
API[2] && centerScript(API);
break;
default:
DoLog('API is {}'.replace('{}', API));
}
}
function centerScript(API) {
switch(API[3]) {
case undefined:
pageScript();
break;
case 'code':
pageCode();
break;
case 'feedback':
pageFeedback();
break;
}
}
function commons() {
// Your common actions here...
}
function pageScript() {
addFavPanel();
}
function pageCode() {
addFavPanel();
}
function pageFeedback() {
addFavPanel();
}
function addFavPanel() {
if (!getUserpage()) {return false;}
GUI();
function GUI() {
// Get elements
const script_after = $('#script-feedback-suggestion+*') || $('#new-script-discussion');
const script_parent = script_after.parentElement;
// My elements
const script_favorite = $CrE('div');
script_favorite.id = 'script-favorite';
script_favorite.style.margin = '0.75em 0';
script_favorite.innerHTML = CONST.Text[i18n].FavEdit;
const favorite_groups = $CrE('select');
favorite_groups.id = 'favorite-groups';
const stored_sets = GM_getValue('script-sets', {sets: []}).sets;
for (const set of stored_sets) {
// Make