Skip to content

Commit

Permalink
Add settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Morea committed Oct 22, 2023
1 parent 3846b1e commit 4c518d1
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 27 deletions.
29 changes: 18 additions & 11 deletions Find Unique Titles/config/userscript.config.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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",
},
};
79 changes: 73 additions & 6 deletions Find Unique Titles/dist/find.unique.titles.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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==

Expand All @@ -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); } }
Expand All @@ -65,6 +68,8 @@ function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r





function hideTorrents(request) {
request.dom.style.display = "none";
for (var torrent of request.torrents) {
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 ***!
Expand Down
2 changes: 1 addition & 1 deletion Find Unique Titles/package.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
5 changes: 3 additions & 2 deletions Find Unique Titles/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
- Add support for GPW
13 changes: 6 additions & 7 deletions Find Unique Titles/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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)
) {
Expand All @@ -70,7 +69,7 @@ const main = async function () {
}
const response = await targetTracker.canUpload(
request,
only_show_unique_titles
settings.onlyNewTitles
);
updateCount(i++);
if (!response) {
Expand Down
67 changes: 67 additions & 0 deletions Find Unique Titles/src/settings.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 4c518d1

Please sign in to comment.