From 4c518d1cc043036425972e00dd06f95dca6a1d96 Mon Sep 17 00:00:00 2001 From: Morea Date: Sun, 22 Oct 2023 12:08:31 +0200 Subject: [PATCH] Add settings UI --- .../config/userscript.config.ts | 29 ++++--- .../dist/find.unique.titles.user.js | 79 +++++++++++++++++-- Find Unique Titles/package.json | 2 +- Find Unique Titles/readme.md | 5 +- Find Unique Titles/src/index.ts | 13 ++- Find Unique Titles/src/settings.ts | 67 ++++++++++++++++ 6 files changed, 168 insertions(+), 27 deletions(-) create mode 100644 Find Unique Titles/src/settings.ts diff --git a/Find Unique Titles/config/userscript.config.ts b/Find Unique Titles/config/userscript.config.ts index 5e106cf..51e87e8 100644 --- a/Find Unique Titles/config/userscript.config.ts +++ b/Find Unique Titles/config/userscript.config.ts @@ -1,22 +1,22 @@ -import pkg from '../package.json' -import type { UserscriptOptions } from 'webpack-userscript' +import pkg from "../package.json"; +import type { UserscriptOptions } from "webpack-userscript"; interface IWebpackUserScript { /* userscript version */ - scriptVersion: string + scriptVersion: string; /* homepage url (github pages) */ - scriptHomePage: string + scriptHomePage: string; /* script file name, without file extension */ - scriptFileName: string + scriptFileName: string; /** * userscript headers * including script name, description, match url, grants and so on * see https://www.tampermonkey.net/documentation.php for details **/ - scriptHeaders: UserscriptOptions['headers'] + scriptHeaders: UserscriptOptions["headers"]; } export const UserScriptConfig: IWebpackUserScript = { @@ -55,12 +55,19 @@ export const UserScriptConfig: IWebpackUserScript = { "https://ptchdbits.co/torrents.php*", "https://hdsky.me/torrents.php*", "https://www.cinematik.net/browse.php*", - "https://pterclub.com/torrents.php*" + "https://pterclub.com/torrents.php*", ], require: [ `https://cdn.jsdelivr.net/npm/jquery@${pkg.dependencies.jquery}/dist/jquery.min.js`, + "https://openuserjs.org/src/libs/sizzle/GM_config.js", ], - grant: ["GM.xmlHttpRequest", "GM.setValue", "GM.getValue"], - updateURL: 'https://github.com/Moreasan/trackers-userscripts/blob/master/Find%20Unique%20Titles/dist/find.unique.titles.user.js' - } -} + grant: [ + "GM.xmlHttpRequest", + "GM.setValue", + "GM.getValue", + "GM_registerMenuCommand", + ], + updateURL: + "https://github.com/Moreasan/trackers-userscripts/blob/master/Find%20Unique%20Titles/dist/find.unique.titles.user.js", + }, +}; diff --git a/Find Unique Titles/dist/find.unique.titles.user.js b/Find Unique Titles/dist/find.unique.titles.user.js index 94e5c1a..73fc156 100644 --- a/Find Unique Titles/dist/find.unique.titles.user.js +++ b/Find Unique Titles/dist/find.unique.titles.user.js @@ -34,8 +34,10 @@ // @grant GM.xmlHttpRequest // @grant GM.setValue // @grant GM.getValue +// @grant GM_registerMenuCommand // @namespace http://tampermonkey.net/ // @require https://cdn.jsdelivr.net/npm/jquery@^3.6.4/dist/jquery.min.js +// @require https://openuserjs.org/src/libs/sizzle/GM_config.js // @updateURL https://github.com/Moreasan/trackers-userscripts/blob/master/Find%20Unique%20Titles/dist/find.unique.titles.user.js // ==/UserScript== @@ -55,6 +57,7 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var _utils_cache__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils/cache */ "./src/utils/cache.ts"); /* harmony import */ var _utils_dom__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils/dom */ "./src/utils/dom.ts"); /* harmony import */ var common__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! common */ "../common/dist/index.mjs"); +/* harmony import */ var _settings__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./settings */ "./src/settings.ts"); var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_trackers__WEBPACK_IMPORTED_MODULE_0__, _utils_cache__WEBPACK_IMPORTED_MODULE_1__]); ([_trackers__WEBPACK_IMPORTED_MODULE_0__, _utils_cache__WEBPACK_IMPORTED_MODULE_1__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__); function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } @@ -65,6 +68,8 @@ function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r + + function hideTorrents(request) { request.dom.style.display = "none"; for (var torrent of request.torrents) { @@ -77,10 +82,7 @@ var main = /*#__PURE__*/function () { console.log("Init User script"); /******************************************************************************/ - - var only_show_unique_titles = false; // change to true if you wish - var better_constant = 1.15; // you can change this too.. wouldn't recommend going below 1.05 - var useCache = false; + var settings = (0,_settings__WEBPACK_IMPORTED_MODULE_4__.getSettings)(); /******************************************************************************/ if (document.getElementById("tracker-select")) return; @@ -116,12 +118,12 @@ var main = /*#__PURE__*/function () { var item = _step.value; { var request = item; - if (useCache && request.imdbId && (0,_utils_cache__WEBPACK_IMPORTED_MODULE_1__.existsInCache)(targetTracker.name(), request.imdbId)) { + if (settings.useCache && request.imdbId && (0,_utils_cache__WEBPACK_IMPORTED_MODULE_1__.existsInCache)(targetTracker.name(), request.imdbId)) { hideTorrents(request); (0,_utils_dom__WEBPACK_IMPORTED_MODULE_2__.updateCount)(i++); continue; } - var response = yield targetTracker.canUpload(request, only_show_unique_titles); + var response = yield targetTracker.canUpload(request, settings.onlyNewTitles); (0,_utils_dom__WEBPACK_IMPORTED_MODULE_2__.updateCount)(i++); if (!response) { if (request.imdbId) { @@ -180,6 +182,71 @@ __webpack_async_result__(); /***/ }), +/***/ "./src/settings.ts": +/*!*************************!*\ + !*** ./src/settings.ts ***! + \*************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "getSettings": () => (/* binding */ getSettings) +/* harmony export */ }); +var defaultConfig = { + onlyNewTitles: false, + useCache: true, + sizeDifferenceThreshold: 1.2 +}; + +// Initialize the library +GM_config.init({ + id: "find-unique-titles-settings", + title: "Find Unique Titles", + fields: { + onlyNewTitles: { + label: "Only new titles", + type: "checkbox", + default: defaultConfig.onlyNewTitles + }, + useCache: { + label: "Use cache", + type: "checkbox", + default: defaultConfig.useCache + }, + sizeDifferenceThreshold: { + label: "Size Difference Threshold", + type: "float", + default: defaultConfig.sizeDifferenceThreshold + } + }, + css: "\n #find-unique-titles-settings {\n }\n #find-unique-titles-settings .config_var {\n display: flex;\n align-items: center;\n justify-content: space-between;\n }\n ", + events: { + open: function open() { + GM_config.frame.style.width = "400px"; // Adjust width as needed + GM_config.frame.style.height = "250px"; // Adjust width as needed + GM_config.frame.style.position = "fixed"; + GM_config.frame.style.left = "50%"; + GM_config.frame.style.top = "50%"; + GM_config.frame.style.transform = "translate(-50%, -50%)"; + }, + save: function save() { + GM_config.close(); + } + } +}); + +// Add menu command to open the configuration +GM_registerMenuCommand("Settings", () => GM_config.open()); +var getSettings = () => { + return { + onlyNewTitles: GM_config.get("onlyNewTitles"), + useCache: GM_config.get("useCache"), + sizeDifferenceThreshold: GM_config.get("sizeDifferenceThreshold") + }; +}; + +/***/ }), + /***/ "./src/trackers/Aither.ts": /*!********************************!*\ !*** ./src/trackers/Aither.ts ***! diff --git a/Find Unique Titles/package.json b/Find Unique Titles/package.json index a51fd40..b739810 100644 --- a/Find Unique Titles/package.json +++ b/Find Unique Titles/package.json @@ -1,7 +1,7 @@ { "name": "find.unique.titles", "description": "Find unique titles to cross seed", - "version": "0.0.1", + "version": "0.0.2", "author": { "name": "Mea01" }, diff --git a/Find Unique Titles/readme.md b/Find Unique Titles/readme.md index 5edf6dd..ac2cdd2 100644 --- a/Find Unique Titles/readme.md +++ b/Find Unique Titles/readme.md @@ -2,7 +2,7 @@ Find Unique Titles is a user script that allow finding content to upload from ot # Install You copy paste the content of the file `dist/find.unique.titles.user.js`. -You can generate it by running run `npm run dev`. +You can generate it by running run `npm run dev`. # Changelog ## 2023-10 @@ -12,9 +12,10 @@ You can generate it by running run `npm run dev`. - Refactor code to use generator for creating search requests. It is essentially practical when you need to do some fetching to build the request (like fetching another page for IMDB id). - Add support for CHD and HDSky (thanks to @gawain12) - PTP can be used a source +- Add a settings panel to configure the script (breaking change) ## 2023-09-30 - Add support for BHD page - Fix an issue where TV content is shown as new content in PTP -- Add support for GPW \ No newline at end of file +- Add support for GPW diff --git a/Find Unique Titles/src/index.ts b/Find Unique Titles/src/index.ts index e053937..c038f16 100644 --- a/Find Unique Titles/src/index.ts +++ b/Find Unique Titles/src/index.ts @@ -7,9 +7,11 @@ import { updateCount, updateNewContent, updateTotalCount, - hideMessageBox, } from "./utils/dom"; import tracker_tools from "common"; +import "./settings"; +import { getSettings } from "./settings"; + function hideTorrents(request: Request) { request.dom.style.display = "none"; for (let torrent of request.torrents) { @@ -22,10 +24,7 @@ const main = async function () { console.log("Init User script"); /******************************************************************************/ - - let only_show_unique_titles = false; // change to true if you wish - let better_constant = 1.15; // you can change this too.. wouldn't recommend going below 1.05 - let useCache = false; + const settings = getSettings(); /******************************************************************************/ if (document.getElementById("tracker-select")) return; @@ -60,7 +59,7 @@ const main = async function () { for await (const item of requestGenerator) { const request = item as Request; if ( - useCache && + settings.useCache && request.imdbId && existsInCache(targetTracker.name(), request.imdbId) ) { @@ -70,7 +69,7 @@ const main = async function () { } const response = await targetTracker.canUpload( request, - only_show_unique_titles + settings.onlyNewTitles ); updateCount(i++); if (!response) { diff --git a/Find Unique Titles/src/settings.ts b/Find Unique Titles/src/settings.ts new file mode 100644 index 0000000..71a5e3f --- /dev/null +++ b/Find Unique Titles/src/settings.ts @@ -0,0 +1,67 @@ +const defaultConfig: Settings = { + onlyNewTitles: false, + useCache: true, + sizeDifferenceThreshold: 1.2, +}; + +// Initialize the library +GM_config.init({ + id: "find-unique-titles-settings", + title: "Find Unique Titles", + fields: { + onlyNewTitles: { + label: "Only new titles", + type: "checkbox", + default: defaultConfig.onlyNewTitles, + }, + useCache: { + label: "Use cache", + type: "checkbox", + default: defaultConfig.useCache, + }, + sizeDifferenceThreshold: { + label: "Size Difference Threshold", + type: "float", + default: defaultConfig.sizeDifferenceThreshold, + }, + }, + css: ` + #find-unique-titles-settings { + } + #find-unique-titles-settings .config_var { + display: flex; + align-items: center; + justify-content: space-between; + } + `, + events: { + open: function () { + GM_config.frame.style.width = "400px"; // Adjust width as needed + GM_config.frame.style.height = "250px"; // Adjust width as needed + GM_config.frame.style.position = "fixed"; + GM_config.frame.style.left = "50%"; + GM_config.frame.style.top = "50%"; + GM_config.frame.style.transform = "translate(-50%, -50%)"; + }, + save: function () { + GM_config.close(); + }, + }, +}); + +// Add menu command to open the configuration +GM_registerMenuCommand("Settings", () => GM_config.open()); + +export const getSettings = (): Settings => { + return { + onlyNewTitles: GM_config.get("onlyNewTitles"), + useCache: GM_config.get("useCache"), + sizeDifferenceThreshold: GM_config.get("sizeDifferenceThreshold"), + }; +}; + +interface Settings { + useCache: boolean; + onlyNewTitles: boolean; + sizeDifferenceThreshold: number; +}