Worm Story Search: Change Threadmark page link to Thread page link

Remove the `/threadmarks` at the end of all SV/SB/QQ URLs to have them go to the thread page instead of the threadmarks page

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           Worm Story Search: Change Threadmark page link to Thread page link
// @namespace      https://github.com/w4tchdoge
// @version        1.0.1-20241208_120940
// @description    Remove the `/threadmarks` at the end of all SV/SB/QQ URLs to have them go to the thread page instead of the threadmarks page
// @author         w4tchdoge
// @homepage       https://github.com/w4tchdoge/MISC-UserScripts
// @match          *://wormstorysearch.com/*
// @match          *://www.wormstorysearch.com/*
// @icon           http://wormstorysearch.com/favicon.png
// @run-at         document-idle
// @license        AGPL-3.0-or-later
// @history        1.0.1 — Make the links to threads use HTTPS
// @history        1.0.0 — Initial commit
// ==/UserScript==

(function () {
	`use strict`;

	// Get Table Rows
	const table_rows = document.querySelector('#stories-searchable-table tbody.rows');

	// Get Array of Stories
	const stories_arr = Array.from(table_rows.children);

	// Iterate on the array of Stories
	stories_arr.forEach((storyELM) => {

		Array.from(storyELM.querySelectorAll('td.title a[data-track][href*="/threads/"]')).forEach((elm, index, arr) => {
			const re_wu = /(https?:\/\/forums?\..*?\.com\/threads\/).*\.(\d+\/)/gmi;    /* Regex for extracting work URL without thread name */
			const re_pgnum = /(page-\d+)|(reader.)|(threadmarks.?)/i;

			const initial_url = new URL(elm.getAttribute(`href`));
			const output_url = `https://${initial_url.hostname}${initial_url.pathname.split(re_pgnum).at(0)}`.replace(re_wu, `$1$2`).slice(0, -1);

			// console.log(`#${index + 1}. ${output_url}`);

			elm.setAttribute(`href`, output_url);
		});

	});
})();