// ==UserScript==
// @name 141 Auto-rate and Duplicate Title Checker
// @namespace http://tampermonkey.net/
// @version 1.31
// @description Separate auto-rate and duplicate title checking functionalities for 141love.net
// @author Your Name
// @match https://141love.net/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
code
// Function for Auto-rating Functionality
const currentIndex = { value: 0 }; // Object to keep track of the current index of the rate button, allows pass by reference
const maxRetries = 5; // Max retries for score input fields
const retryDelay = 500; // Delay between retries in milliseconds
// User-specific ratings logic
const ratingLogic = {
"Juven": { score1: 5, score2: 50, score4: 5 },
"力王ER": { score1: 5, score2: 50, score4: 5 },
// Add more usernames and ratings as needed
};
// Default rating if username is not found
const defaultRating = { score1: 2, score2: 20, score4: 2 };
// Function to update inputs and submit the rating form
function updateInputsAndSubmit(button, retries = 0) {
const postElement = button.closest('.plhin');
if (!postElement) {
console.error('Could not find the post element associated with this button.');
return;
}
const score1 = document.querySelector('input#score1.px.z');
const score2 = document.querySelector('input#score2.px.z');
const score4 = document.querySelector('input#score4.px.z');
const usernameElement = postElement.querySelector('div.authi a.xw1');
const username = usernameElement ? usernameElement.innerText.trim() : '';
let rating = ratingLogic[username] || defaultRating;
if (score1 && score2 && score4) {
score1.value = rating.score1;
score2.value = rating.score2;
score4.value = rating.score4;
console.log(`Setting scores for user: ${username}`);
// Simulate form submission
const form = document.querySelector('form#rateform');
if (form) {
form.dispatchEvent(new Event('submit', { cancelable: true }));
} else {
console.error('Form not found.');
}
} else {
console.error('Score input fields are missing.');
if (retries < maxRetries) {
console.log(`Retrying to find score inputs... (${retries + 1}/${maxRetries})`);
setTimeout(() => updateInputsAndSubmit(button, retries + 1), retryDelay);
} else {
console.warn('Max retries exceeded for finding score input fields. Moving to next rate button.');
currentIndex.value++;
setTimeout(clickNextRateButton, 1000);
}
}
}
// Click next rate button and handle logic
function clickNextRateButton() {
const rateButtons = Array.from(document.querySelectorAll('a.rateb'));
if (currentIndex.value >= rateButtons.length) {
console.log('All replies have been rated.');
return;
}
const button = rateButtons[currentIndex.value];
const postElement = button.closest('.plhin');
if (shouldIgnoreMessage(postElement)) {
console.log(`Ignoring post ${currentIndex.value + 1}.`);
currentIndex.value++;
setTimeout(clickNextRateButton, 1000);
return;
}
updateInputsAndSubmit(button);
currentIndex.value++;
// Schedule the next iteration after a delay
setTimeout(clickNextRateButton, 1000);
}
// Function to decide if a message should be ignored
function shouldIgnoreMessage(postElement) {
const messageElement = postElement.querySelector('.t_f');
const messageHTML = messageElement ? messageElement.innerHTML.trim() : '';
// Define ignore patterns for common phrases
const ignorePatterns = [
/^[^\W_]{0,5}感[谢謝].*?分享(?!\s)([^\W_]{0,5}|.*)$/i,
/^[^\W_]{0,5}多[谢謝].*?分享(?!\s)([^\W_]{0,5}|.*)$/i,
/^[^\W_]{0,5}(多?[谢謝]{2})(?!\s)([^\W_]{0,5}|.*)$/i,
/非常精彩/i,
/無撚得頂/i,
/(thx|thanks|thank\s+you)\s+for\s+sharing.*$/i,
/(T.*?Q|thx|thanks).*$/i,
/^[^\W_]{0,5}nice\s*([^\W_]{0,5}|.*)$/i,
/^[^\W_]{0,5}good\s*([^\W_]{0,5}|.*)$/i,
];
// Clean up message for analysis
const cleanedMessage = messageHTML
.replace(/<br\s*\/?>/g, ' ') // Normalize break tags
.replace(/<img[^>]*src="[^"]*\.gif"[^>]*>/g, ' ') // Remove GIF images
.replace(/<img[^>]*>/g, ' ') // Replace other images with space
.replace(/ /g, ' ') // Normalize non-breaking spaces
.replace(/\s+/g, ' ') // Collapse multiple spaces into a single space
.trim(); // Trim leading/trailing whitespace
const hasMeaningfulContent = cleanedMessage.length > 0; // Check for meaningful content
return !hasMeaningfulContent; // Ignore if no meaningful content
}
// Part 2: Duplicate Title Detection
function checkForDuplicateTitles() {
const titles = Array.from(document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst'));
const titleCounts = {};
const duplicateTitles = [];
titles.forEach(titleElement => {
const title = titleElement.innerText.trim();
titleCounts[title] = (titleCounts[title] || 0) + 1;
if (titleCounts[title] > 1 && !duplicateTitles.includes(title)) {
duplicateTitles.push(title);
}
});
if (duplicateTitles.length > 0) {
alert('Warning: There are duplicate thread titles on this page!');
highlightDuplicates(duplicateTitles);
}
}
// Function to highlight duplicate titles
function highlightDuplicates(duplicateTitles) {
const titles = document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst');
titles.forEach(titleElement => {
if (duplicateTitles.includes(titleElement.innerText.trim())) {
titleElement.style.backgroundColor = 'yellow'; // Highlight duplicate titles
}
});
}
// Function to initiate auto-rating
function automateRating() {
currentIndex.value = 0; // Reset the index
clickNextRateButton(); // Start clicking buttons for auto-rating
}
// Function to add automation button to the UI
function addAutomationButton(container, buttonText, styles, buttonClass) {
if (container) {
const autoButton = document.createElement('button');
autoButton.innerText = buttonText;
autoButton.onclick = automateRating;
Object.assign(autoButton.style, styles);
autoButton.className = buttonClass;
container.appendChild(autoButton);
}
}
// Add custom button styles
const style = document.createElement('style');
style.textContent = `
.main-button {
background-color: #FE9510;
color: white;
border: none;
border-radius: 4px;
padding: 7px 10px;
font-size: 14.5px;
cursor: pointer;
margin: 0px;
transition: background-color 0.3s, color 0.3s;
}
.main-button:hover {
background-color: #E78F1B;
color: #FFF;
}
`;
document.head.appendChild(style);
// Adding automation buttons after the page loads
window.addEventListener('load', () => {
if (window.location.href.includes("thread") && document.querySelector('a.rateb')) {
// On pages with rating buttons, add auto-rate button
addAutomationButton(document.querySelector('div#pgt.pgs.cl'), '自動評分', {}, 'main-button');
} else if (document.querySelector('div.bm_c')) {
// On pages with div.bm_c, perform duplicate check
checkForDuplicateTitles();
addAutomationButton(document.querySelector('div.bm_c'), '檢查重複標題', {}, 'main-button'); // Button for duplicate check if needed
} else {
console.log('Not a valid page for auto-rating or duplicate checking. Buttons will not be added.');
}
});
})();
Please help me extract the title duplication check section of this script and put it in a new script.
Assistant
Certainly! Below is a separate script that focuses solely on the title duplication check functionality extracted from your original script:
javascript
User
does it check inside div.bm_c?
Assistant
Yes, the script does check for duplicate titles specifically within the div.bm_c container. Here's a breakdown of how it works:
Selecting Titles: The line of code that selects the titles is using a CSS selector that looks for elements matching the criteria within div.bm_c:
This selector will find all <a> elements with a class of s xst inside tbody elements that have an ID starting with normalthread_, all of which must be children of div.bm_c.
Duplicate Checking Logic: It then processes each title found in that selection for duplicate detection, tracking the count of each title in the titleCounts object and gathering duplicates in the duplicateTitles array if a title appears more than once.
Highlighting Duplicates: If duplicates are found, the script highlights those titles by changing their background color.
Confirmation of Functionality
If div.bm_c exists on the page, the button to check for duplicates will be added.
When the button is clicked, it triggers the checkForDuplicateTitles function which only examines titles under the div.bm_c container.
Here’s the relevant part again for clarity, confirming that the checking is indeed performed within div.bm_c:
javascript
window.addEventListener('load', () => {
if (document.querySelector('div.bm_c')) {
// On pages with div.bm_c, add the duplicate check button
addDuplicateCheckButton(document.querySelector('div.bm_c'), '檢查重複標題', {}, 'main-button');
}
});
Since this script is designed to work with the structure of the 141love.net site and its identification of threads, the logic is specifically tailored to focus its checks within the context of the div.bm_c section of the HTML.
User
Assistant
I see that the table containing the thread titles is structured with a set of <tbody> elements under a table <tbody id="threadlisttableid">, where the actual titles are found in an <a> tag with classes s xst. The script I provided should work for this HTML structure assuming the correct title elements are being targeted, but if there are nuances in how the titles are presented or how the query selectors are set up, that could lead to issues.
Adjusting the Duplicate Title Checker
To make sure it finds the duplicate titles in your provided HTML structure, here's the adjusted checkForDuplicateTitles function that should correctly parse the titles:
javascript
User
it is not working...
Could you just use these functions?
code
// Part 2: Duplicate Title Detection
function checkForDuplicateTitles() {
const titles = Array.from(document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst'));
const titleCounts = {};
const duplicateTitles = [];
titles.forEach(titleElement => {
const title = titleElement.innerText.trim();
titleCounts[title] = (titleCounts[title] || 0) + 1;
if (titleCounts[title] > 1 && !duplicateTitles.includes(title)) {
duplicateTitles.push(title);
}
});
if (duplicateTitles.length > 0) {
alert('Warning: There are duplicate thread titles on this page!');
highlightDuplicates(duplicateTitles);
}
}
// Function to highlight duplicate titles
function highlightDuplicates(duplicateTitles) {
const titles = document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst');
titles.forEach(titleElement => {
if (duplicateTitles.includes(titleElement.innerText.trim())) {
titleElement.style.backgroundColor = 'yellow'; // Highlight duplicate titles
}
});
}
Assistant
Certainly! Below is a simplified userscript that focuses solely on the functions you've provided for detecting and highlighting duplicate thread titles on the 141love.net forum. This code includes the necessary event listener to invoke these functions when the page is loaded.
javascript
User
it is not able to detect the duplicate titles.
Assistant
Let’s troubleshoot the duplicate title detection functionality in your userscript. Given your HTML structure, we want to ensure that we can accurately select the elements containing the thread titles and correctly identify duplicates.
Here’s a refined version of the script that will specifically work with the structure you provided earlier:
javascript
User
貼圖教學
141影片
金僑
富士
合宜
華源
香檳
基隆
鴨寮
大南
鴻聯
五寶
福樂
喜利
康寧
樂昌
群星
興隆
錦邦
皇后
鳳鳴
富士
南方
太安
gtag('config', 'G-G02LH4ZZWX');
it is still not working. THis is the page source. Will it help you fix the problem?
Assistant
Thank you for providing the complete HTML structure of the page. Based on the structure presented, it appears that the script for checking duplicate titles should work as intended since it correctly targets the thread titles defined in your HTML.
Let’s review the relevant parts of your HTML and modify the script accordingly to ensure it captures the titles accurately.
Key Elements from Your HTML Structure:
The thread titles are located in the th.common elements with a specific anchor tag <a> that contains the class .s.xst.
The IDs for the tbody elements encapsulating thread details start with normalthread_.
Adjusted Userscript:
Below is the adjusted userscript, incorporating best practices and ensuring we work with the specific HTML you've provided. It also includes debugging logs to help identify if titles are being captured correctly.
javascript
User
// ==UserScript==
// @name 141 Auto-rate and Duplicate Title Checker
// @namespace http://tampermonkey.net/
// @version 1.31
// @description Separate auto-rate and duplicate title checking functionalities for 141love.net
// @author Your Name
// @match https://141love.net/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
code
Assistant
Absolutely! Let's integrate the working parts of your duplicate title detection functionality with the auto-rating functionality from your script. I'll ensure that both functionalities are clearly separated but included in the same userscript so they can work together effectively.
Combined Script:
Here's the combined userscript that implements both auto-rating and duplicate title checking:
javascript
User
But I dont' want the auto-rating...I just want you to fix your script using the given script. do you add unnecessary functions your your script.
Assistant
Got it! I apologize for the confusion. Let’s focus solely on the duplicate title detection functionality and use the provided script structure you have. We will ensure to keep it simple, without any unnecessary features related to auto-rating.
Below is the cleaned-up userscript that incorporates only the duplicate title detection functionality based on the provided script design. This version will only check for duplicates and highlight them as necessary.
Simplified Duplicate Title Checker Script
javascript
User
there is no need for the 檢查重複標題 button. When it sees div.bm_c, it will automatically gives out the warning and highlight the duplicate titles.
Assistant
Understood! We can simplify the script to automatically check for duplicate thread titles when a page with div.bm_c is loaded. The script will issue an alert with duplicates and highlight them without requiring a button click.
Here’s the updated userscript that integrates these functionalities:
Auto Duplicate Title Checker Script
javascript
// ==UserScript==
// @name Auto Duplicate Title Checker for 141love.net
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Automatically checks for duplicate thread titles on 141love.net when a relevant page is loaded.
// @author Your Name
// @match https://141love.net/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Function to check for duplicate titles
function checkForDuplicateTitles() {
const titles = Array.from(document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst'));
const titleCounts = {};
const duplicateTitles = [];
titles.forEach(titleElement => {
const title = titleElement.innerText.trim(); // Get the title text and trim whitespace
titleCounts[title] = (titleCounts[title] || 0) + 1; // Count occurrences of each title
if (titleCounts[title] > 1 && !duplicateTitles.includes(title)) {
duplicateTitles.push(title); // Store duplicate titles
}
});
if (duplicateTitles.length > 0) {
alert('Warning: There are duplicate thread titles on this page!');
highlightDuplicates(duplicateTitles); // Highlight duplicates
}
}
// Function to highlight duplicate titles
function highlightDuplicates(duplicateTitles) {
const titles = document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst');
titles.forEach(titleElement => {
if (duplicateTitles.includes(titleElement.innerText.trim())) {
titleElement.style.backgroundColor = 'yellow'; // Highlight duplicate titles
titleElement.style.fontWeight = 'bold'; // Optionally make the text bold
}
});
}
// Automatically check for duplicates when the page loads
window.addEventListener('load', () => {
const bmContainer = document.querySelector('div.bm_c'); // Find the main container for threads
if (bmContainer) {
checkForDuplicateTitles(); // Automatically perform the duplicate check
}
});
})();
Not yet included in a published release.
// ==UserScript==
// @name Duplicate Title Checker for 141love.net
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Check for duplicate thread titles on 141love.net
// @author Your Name
// @match https://141love.net/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Function to check for duplicate titles
function checkForDuplicateTitles() {
const titles = Array.from(document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst'));
const titleCounts = {};
const duplicateTitles = [];
titles.forEach(titleElement => {
const title = titleElement.innerText.trim();
titleCounts[title] = (titleCounts[title] || 0) + 1;
if (titleCounts[title] > 1 && !duplicateTitles.includes(title)) {
duplicateTitles.push(title);
}
});
if (duplicateTitles.length > 0) {
alert('Warning: There are duplicate thread titles on this page!');
highlightDuplicates(duplicateTitles);
}
}
// Function to highlight duplicate titles
function highlightDuplicates(duplicateTitles) {
const titles = document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst');
titles.forEach(titleElement => {
if (duplicateTitles.includes(titleElement.innerText.trim())) {
titleElement.style.backgroundColor = 'yellow'; // Highlight duplicate titles
}
});
}
// Function to add duplicate check button to the UI
function addDuplicateCheckButton(container, buttonText, styles, buttonClass) {
if (container) {
const checkButton = document.createElement('button');
checkButton.innerText = buttonText;
checkButton.onclick = checkForDuplicateTitles;
Object.assign(checkButton.style, styles);
checkButton.className = buttonClass;
container.appendChild(checkButton);
}
}
// Add custom button styles
const style = document.createElement('style');
style.textContent = `
.main-button {
background-color: #FE9510;
color: white;
border: none;
border-radius: 4px;
padding: 7px 10px;
font-size: 14.5px;
cursor: pointer;
margin: 0px;
transition: background-color 0.3s, color 0.3s;
}
.main-button:hover {
background-color: #E78F1B;
color: #FFF;
}
`;
document.head.appendChild(style);
// Adding the duplicate check button after the page loads
window.addEventListener('load', () => {
if (document.querySelector('div.bm_c')) {
// On pages with div.bm_c, add the duplicate check button
addDuplicateCheckButton(document.querySelector('div.bm_c'), '檢查重複標題', {}, 'main-button');
} else {
console.log('Not a valid page for duplicate checking. Button will not be added.');
}
});
})();
Explanation of the New Script:
Name & Metadata: It has been given a new name and relevant metadata for a userscript.
Duplicate Title Check Logic: The logic for checking duplicate titles and highlighting them is preserved.
Button Creation: A button to trigger the duplicate title check is included.
Styles: The styles for the button are retained to maintain a consistent appearance.
Event Listener: The script adds the button to the page after it loads, similar to the original.
You can save this code as a new userscript in your Tampermonkey or a similar userscript manager. Adjust the @match or other metadata sections as needed to fit your requirements.
// ==UserScript==
// @name Duplicate Title Checker for 141love.net
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Check for duplicate thread titles on 141love.net
// @author Your Name
// @match https://141love.net/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Function to check for duplicate titles
function checkForDuplicateTitles() {
// Select title elements specifically under the appropriate container
const titles = Array.from(document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst'));
const titleCounts = {};
const duplicateTitles = [];
titles.forEach(titleElement => {
const title = titleElement.innerText.trim();
titleCounts[title] = (titleCounts[title] || 0) + 1;
if (titleCounts[title] > 1 && !duplicateTitles.includes(title)) {
duplicateTitles.push(title);
}
});
if (duplicateTitles.length > 0) {
alert('Warning: There are duplicate thread titles on this page!');
highlightDuplicates(duplicateTitles);
} else {
alert('No duplicate thread titles found.');
}
}
// Function to highlight duplicate titles
function highlightDuplicates(duplicateTitles) {
const titles = document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst');
titles.forEach(titleElement => {
if (duplicateTitles.includes(titleElement.innerText.trim())) {
titleElement.style.backgroundColor = 'yellow'; // Highlight duplicate titles
}
});
}
// Function to add duplicate check button to the UI
function addDuplicateCheckButton(container) {
if (container) {
const checkButton = document.createElement('button');
checkButton.innerText = 'Check for Duplicate Titles';
checkButton.onclick = checkForDuplicateTitles;
// Add button styles
checkButton.style.backgroundColor = "#FE9510";
checkButton.style.color = "white";
checkButton.style.border = "none";
checkButton.style.borderRadius = "4px";
checkButton.style.padding = "7px 10px";
checkButton.style.fontSize = "14.5px";
checkButton.style.cursor = "pointer";
container.appendChild(checkButton);
}
}
// Adding the duplicate check button after the page loads
window.addEventListener('load', () => {
const bmContainer = document.querySelector('div.bm_c');
if (bmContainer) {
addDuplicateCheckButton(bmContainer);
} else {
console.log('Not a valid page for duplicate checking. Button will not be added.');
}
});
})();
Key Changes and Clarifications:
Targeting Titles:
The selector tbody[id^="normalthread_"] a.s.xst ensures we are specifically looking at thread rows that fit the intended criteria.
Alert for Duplicates:
The script alerts whether duplicate titles were found or not.
Button Style:
Some inline styles are added for better visibility and appeal.
Event Listener:
The event listener waits for the page to finish loading and then looks for the div.bm_c to add the button.
Testing
Ensure that the userscript is correctly installed and that Tampermonkey is active on the page where you are looking for duplicates.
After loading a page with several threads under div.bm_c, you should see the button, which when clicked will check for duplicate titles based on the refined logic.
Debugging
If the logic still does not capture duplicates, you could add console.log(title); within the forEach loop to see what titles are being processed and ensure the intended titles are captured. This may help in identifying structural issues with the HTML or misconfigured selectors.
// ==UserScript==
// @name Duplicate Title Checker for 141love.net
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Check for duplicate thread titles on 141love.net
// @author Your Name
// @match https://141love.net/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Part 2: Duplicate Title Detection
function checkForDuplicateTitles() {
const titles = Array.from(document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst'));
const titleCounts = {};
const duplicateTitles = [];
titles.forEach(titleElement => {
const title = titleElement.innerText.trim();
titleCounts[title] = (titleCounts[title] || 0) + 1;
if (titleCounts[title] > 1 && !duplicateTitles.includes(title)) {
duplicateTitles.push(title);
}
});
if (duplicateTitles.length > 0) {
alert('Warning: There are duplicate thread titles on this page!');
highlightDuplicates(duplicateTitles);
} else {
alert('No duplicate thread titles found.');
}
}
// Function to highlight duplicate titles
function highlightDuplicates(duplicateTitles) {
const titles = document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst');
titles.forEach(titleElement => {
if (duplicateTitles.includes(titleElement.innerText.trim())) {
titleElement.style.backgroundColor = 'yellow'; // Highlight duplicate titles
}
});
}
// Function to add duplicate check button to the UI
function addDuplicateCheckButton(container) {
if (container) {
const checkButton = document.createElement('button');
checkButton.innerText = 'Check for Duplicate Titles';
checkButton.onclick = checkForDuplicateTitles;
// Add button styles
checkButton.style.backgroundColor = "#FE9510";
checkButton.style.color = "white";
checkButton.style.border = "none";
checkButton.style.borderRadius = "4px";
checkButton.style.padding = "7px 10px";
checkButton.style.fontSize = "14.5px";
checkButton.style.cursor = "pointer";
checkButton.style.margin = "10px"; // Add margin for better spacing
container.appendChild(checkButton);
}
}
// Adding the duplicate check button after the page loads
window.addEventListener('load', () => {
const bmContainer = document.querySelector('div.bm_c');
if (bmContainer) {
addDuplicateCheckButton(bmContainer);
} else {
console.log('Not a valid page for duplicate checking. Button will not be added.');
}
});
})();
Explanation of the Script:
Functionality to Check for Duplicates:
It uses the checkForDuplicateTitles function to find all titles under the div.bm_c container based on the previously defined criteria.
Duplicates are stored and highlighted if found.
Highlighting Function:
The highlightDuplicates function highlights duplicate titles by changing their background color to yellow.
Adding a Button:
After the page has loaded, the script adds a button labeled "Check for Duplicate Titles" to the UI to trigger the duplicate check when clicked.
Window Load Event:
The event listener ensures that the button is added only after the content of the page is fully loaded.
Testing the Script
Install this userscript in your Tampermonkey or another userscript manager.
Navigate to any page on 141love.net that contains threads in the specified HTML structure and click the button to perform the duplicate title check.
You should see an alert indicating whether duplicates were found, and any duplicates will be highlighted on the page.
If you encounter issues or if the titles are formatted differently than expected, feel free to reach out!
// ==UserScript==
// @name Duplicate Title Checker for 141love.net
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Check for duplicate thread titles on 141love.net
// @author Your Name
// @match https://141love.net/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Function to check for duplicate titles
function checkForDuplicateTitles() {
// Select thread titles specifically under the appropriate container
const titles = Array.from(document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst'));
const titleCounts = {};
const duplicateTitles = [];
titles.forEach(titleElement => {
const title = titleElement.innerText.trim(); // Get the title text and trim whitespace
titleCounts[title] = (titleCounts[title] || 0) + 1; // Count occurrences of each title
if (titleCounts[title] > 1 && !duplicateTitles.includes(title)) {
duplicateTitles.push(title); // Save duplicates if it appears more than once
}
});
if (duplicateTitles.length > 0) {
alert('Warning: There are duplicate thread titles on this page!');
highlightDuplicates(duplicateTitles); // Call function to highlight duplicates
} else {
alert('No duplicate thread titles found.');
}
}
// Function to highlight duplicate titles
function highlightDuplicates(duplicateTitles) {
const titles = document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst');
titles.forEach(titleElement => {
if (duplicateTitles.includes(titleElement.innerText.trim())) {
titleElement.style.backgroundColor = 'yellow'; // Highlight duplicate titles
titleElement.style.fontWeight = 'bold'; // Optionally make the text bold
}
});
}
// Function to add duplicate check button to the UI
function addDuplicateCheckButton(container) {
if (container) {
const checkButton = document.createElement('button');
checkButton.innerText = 'Check for Duplicate Titles';
checkButton.onclick = checkForDuplicateTitles; // Attach the function to the button click
// Add button styles
checkButton.style.backgroundColor = "#FE9510";
checkButton.style.color = "white";
checkButton.style.border = "none";
checkButton.style.borderRadius = "4px";
checkButton.style.padding = "7px 10px";
checkButton.style.fontSize = "14.5px";
checkButton.style.cursor = "pointer";
checkButton.style.margin = "10px"; // Add margin for better spacing
container.appendChild(checkButton); // Add button to the container
}
}
// Adding the duplicate check button after the page loads
window.addEventListener('load', () => {
const bmContainer = document.querySelector('div.bm_c'); // Find the main container for threads
if (bmContainer) {
addDuplicateCheckButton(bmContainer); // Add the button to the container found
} else {
console.log('Not a valid page for duplicate checking. Button will not be added.');
}
});
})();
Key Points to Ensure Functionality
Selector Accuracy:
The selector div.bm_c tbody[id^="normalthread_"] a.s.xst is specifically looking for the a tags that are children of tbody tags with IDs starting with "normalthread_". Make sure this exactly matches your HTML structure.
Title Retrieval:
Ensure that the thread titles you want to check for duplicates are actually present within the a.s.xst elements as expected. If they are slightly different, adjust the selector accordingly.
Testing Duplicates:
Make sure to run this script on a page that intentionally has duplicates for testing purposes. If you test on a page without duplicates, the script will always report "No duplicate thread titles found."
Debugging:
You can add console.log(title); within the forEach loop to see what titles are being captured. This will help identify if the script is working correctly up to that point.
Example of Debugging Output
Add this inside the titles.forEach loop:
javascript
console.log(title); // Log each title found for debugging
Final Notes
If this revised code still does not work, double-check the following:
Ensure the userscript is enabled in Tampermonkey.
Look for any errors in the browser console that may indicate a problem with DOM access.
Make sure there are visible, duplicate titles in the page you are testing.
With these checks and this refined script, you should be able to detect duplicate titles correctly. If issues persist, feel free to provide further details about the actual DOM structure.
// ==UserScript==
// @name Duplicate Title Checker for 141love.net
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Check for duplicate thread titles on 141love.net
// @author Your Name
// @match https://141love.net/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Function to check for duplicate titles
function checkForDuplicateTitles() {
// Select the thread titles as specified in the provided HTML
const titles = Array.from(document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] th.common a.s.xst'));
const titleCounts = {};
const duplicateTitles = [];
titles.forEach(titleElement => {
const title = titleElement.innerText.trim(); // Get the title text and trim whitespace
titleCounts[title] = (titleCounts[title] || 0) + 1; // Count occurrences of each title
if (titleCounts[title] > 1 && !duplicateTitles.includes(title)) {
duplicateTitles.push(title); // Save duplicates if it appears more than once
}
console.log(`Processing title: ${title}`); // Log titles for debugging
});
if (duplicateTitles.length > 0) {
alert('Warning: There are duplicate thread titles on this page!');
highlightDuplicates(duplicateTitles); // Call function to highlight duplicates
} else {
alert('No duplicate thread titles found.');
}
}
// Function to highlight duplicate titles
function highlightDuplicates(duplicateTitles) {
const titles = document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] th.common a.s.xst');
titles.forEach(titleElement => {
if (duplicateTitles.includes(titleElement.innerText.trim())) {
titleElement.style.backgroundColor = 'yellow'; // Highlight duplicate titles
titleElement.style.fontWeight = 'bold'; // Optional: make the text bold
}
});
}
// Function to add duplicate check button to the UI
function addDuplicateCheckButton(container) {
if (container) {
const checkButton = document.createElement('button');
checkButton.innerText = 'Check for Duplicate Titles';
checkButton.onclick = checkForDuplicateTitles; // Attach the function to the button click
// Add button styles
checkButton.style.backgroundColor = "#FE9510";
checkButton.style.color = "white";
checkButton.style.border = "none";
checkButton.style.borderRadius = "4px";
checkButton.style.padding = "7px 10px";
checkButton.style.fontSize = "14.5px";
checkButton.style.cursor = "pointer";
checkButton.style.margin = "10px"; // Add margin for better spacing
container.appendChild(checkButton); // Add button to the container
}
}
// Adding the duplicate check button after the page loads
window.addEventListener('load', () => {
const bmContainer = document.querySelector('div.bm_c'); // Find the main container for threads
if (bmContainer) {
addDuplicateCheckButton(bmContainer); // Add the button to the container found
} else {
console.log('Not a valid page for duplicate checking. Button will not be added.');
}
});
})();
Key Adjustments Made:
Accurate Selector:
The script now specifically targets the titles inside th.common using the selector div.bm_c tbody[id^="normalthread_"] th.common a.s.xst.
Debugging Logs:
Each time a title is processed, it is logged to the console to help trace what titles are being checked, aiding in debugging.
Highlighting:
Duplicate titles are highlighted in yellow and made bold for visibility.
Testing the Script:
After saving this script in Tampermonkey, navigate to a page with thread titles.
Click the "Check for Duplicate Titles" button and observe the alerts and console for outputs to confirm it processes the titles correctly.
If duplicates exist, the highlighted titles will reflect as expected.
If It Still Doesn't Work:
Make sure the script runs on the correct pages by verifying the URL patterns.
Open the browser console (F12) and look for error messages that could indicate problems in the script logic or DOM selection issues.
Ensure that the script is indeed enabled in Tampermonkey and is running without any conflicting scripts or browser settings.
// Function for Auto-rating Functionality
const currentIndex = { value: 0 }; // Object to keep track of the current index of the rate button, allows pass by reference
const maxRetries = 5; // Max retries for score input fields
const retryDelay = 500; // Delay between retries in milliseconds
// User-specific ratings logic
const ratingLogic = {
"Juven": { score1: 5, score2: 50, score4: 5 },
"力王ER": { score1: 5, score2: 50, score4: 5 },
// Add more usernames and ratings as needed
};
// Default rating if username is not found
const defaultRating = { score1: 2, score2: 20, score4: 2 };
// Function to update inputs and submit the rating form
function updateInputsAndSubmit(button, retries = 0) {
const postElement = button.closest('.plhin');
if (!postElement) {
console.error('Could not find the post element associated with this button.');
return;
}
const score1 = document.querySelector('input#score1.px.z');
const score2 = document.querySelector('input#score2.px.z');
const score4 = document.querySelector('input#score4.px.z');
const usernameElement = postElement.querySelector('div.authi a.xw1');
const username = usernameElement ? usernameElement.innerText.trim() : '';
let rating = ratingLogic[username] || defaultRating;
if (score1 && score2 && score4) {
score1.value = rating.score1;
score2.value = rating.score2;
score4.value = rating.score4;
console.log(`Setting scores for user: ${username}`);
// Simulate form submission
const form = document.querySelector('form#rateform');
if (form) {
form.dispatchEvent(new Event('submit', { cancelable: true }));
} else {
console.error('Form not found.');
}
} else {
console.error('Score input fields are missing.');
if (retries < maxRetries) {
console.log(`Retrying to find score inputs... (${retries + 1}/${maxRetries})`);
setTimeout(() => updateInputsAndSubmit(button, retries + 1), retryDelay);
} else {
console.warn('Max retries exceeded for finding score input fields. Moving to next rate button.');
currentIndex.value++;
setTimeout(clickNextRateButton, 1000);
}
}
}
// Click next rate button and handle logic
function clickNextRateButton() {
const rateButtons = Array.from(document.querySelectorAll('a.rateb'));
if (currentIndex.value >= rateButtons.length) {
console.log('All replies have been rated.');
return;
}
const button = rateButtons[currentIndex.value];
const postElement = button.closest('.plhin');
if (shouldIgnoreMessage(postElement)) {
console.log(`Ignoring post ${currentIndex.value + 1}.`);
currentIndex.value++;
setTimeout(clickNextRateButton, 1000);
return;
}
updateInputsAndSubmit(button);
currentIndex.value++;
// Schedule the next iteration after a delay
setTimeout(clickNextRateButton, 1000);
}
// Function to decide if a message should be ignored
function shouldIgnoreMessage(postElement) {
const messageElement = postElement.querySelector('.t_f');
const messageHTML = messageElement ? messageElement.innerHTML.trim() : '';
// Define ignore patterns for common phrases
const ignorePatterns = [
/^[^\W_]{0,5}感[谢謝].*?分享(?!\s)([^\W_]{0,5}|.*)$/i,
/^[^\W_]{0,5}多[谢謝].*?分享(?!\s)([^\W_]{0,5}|.*)$/i,
/^[^\W_]{0,5}(多?[谢謝]{2})(?!\s)([^\W_]{0,5}|.*)$/i,
/非常精彩/i,
/無撚得頂/i,
/(thx|thanks|thank\s+you)\s+for\s+sharing.*$/i,
/(T.*?Q|thx|thanks).*$/i,
/^[^\W_]{0,5}nice\s*([^\W_]{0,5}|.*)$/i,
/^[^\W_]{0,5}good\s*([^\W_]{0,5}|.*)$/i,
];
// Clean up message for analysis
const cleanedMessage = messageHTML
.replace(/<br\s*\/?>/g, ' ') // Normalize break tags
.replace(/<img[^>]*src="[^"]*\.gif"[^>]*>/g, ' ') // Remove GIF images
.replace(/<img[^>]*>/g, ' ') // Replace other images with space
.replace(/ /g, ' ') // Normalize non-breaking spaces
.replace(/\s+/g, ' ') // Collapse multiple spaces into a single space
.trim(); // Trim leading/trailing whitespace
const hasMeaningfulContent = cleanedMessage.length > 0; // Check for meaningful content
return !hasMeaningfulContent; // Ignore if no meaningful content
}
// Part 2: Duplicate Title Detection
function checkForDuplicateTitles() {
const titles = Array.from(document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst'));
const titleCounts = {};
const duplicateTitles = [];
titles.forEach(titleElement => {
const title = titleElement.innerText.trim();
titleCounts[title] = (titleCounts[title] || 0) + 1;
if (titleCounts[title] > 1 && !duplicateTitles.includes(title)) {
duplicateTitles.push(title);
}
});
if (duplicateTitles.length > 0) {
alert('Warning: There are duplicate thread titles on this page!');
highlightDuplicates(duplicateTitles);
}
}
// Function to highlight duplicate titles
function highlightDuplicates(duplicateTitles) {
const titles = document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst');
titles.forEach(titleElement => {
if (duplicateTitles.includes(titleElement.innerText.trim())) {
titleElement.style.backgroundColor = 'yellow'; // Highlight duplicate titles
}
});
}
// Function to initiate auto-rating
function automateRating() {
currentIndex.value = 0; // Reset the index
clickNextRateButton(); // Start clicking buttons for auto-rating
}
// Function to add automation button to the UI
function addAutomationButton(container, buttonText, styles, buttonClass) {
if (container) {
const autoButton = document.createElement('button');
autoButton.innerText = buttonText;
autoButton.onclick = automateRating;
Object.assign(autoButton.style, styles);
autoButton.className = buttonClass;
container.appendChild(autoButton);
}
}
// Add custom button styles
const style = document.createElement('style');
style.textContent = `
.main-button {
background-color: #FE9510;
color: white;
border: none;
border-radius: 4px;
padding: 7px 10px;
font-size: 14.5px;
cursor: pointer;
margin: 0px;
transition: background-color 0.3s, color 0.3s;
}
.main-button:hover {
background-color: #E78F1B;
color: #FFF;
}
`;
document.head.appendChild(style);
// Adding automation buttons after the page loads
window.addEventListener('load', () => {
if (window.location.href.includes("thread") && document.querySelector('a.rateb')) {
// On pages with rating buttons, add auto-rate button
addAutomationButton(document.querySelector('div#pgt.pgs.cl'), '自動評分', {}, 'main-button');
} else if (document.querySelector('div.bm_c')) {
// On pages with div.bm_c, perform duplicate check
checkForDuplicateTitles();
addAutomationButton(document.querySelector('div.bm_c'), '檢查重複標題', {}, 'main-button'); // Button for duplicate check if needed
} else {
console.log('Not a valid page for auto-rating or duplicate checking. Buttons will not be added.');
}
});
})();
The duplicate title detection part of this script works perfectly. Could you use it to fix your script?
// ==UserScript==
// @name 141 Auto-rate and Duplicate Title Checker
// @namespace http://tampermonkey.net/
// @version 1.32
// @description Auto-rate and duplicate title checking functionalities for 141love.net
// @author Your Name
// @match https://141love.net/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Function for Auto-rating Functionality
const currentIndex = { value: 0 }; // Object to keep track of the current index of the rate button, allows pass by reference
const maxRetries = 5; // Max retries for score input fields
const retryDelay = 500; // Delay between retries in milliseconds
// User-specific ratings logic
const ratingLogic = {
"Juven": { score1: 5, score2: 50, score4: 5 },
"力王ER": { score1: 5, score2: 50, score4: 5 },
// Add more usernames and ratings as needed
};
// Default rating if username is not found
const defaultRating = { score1: 2, score2: 20, score4: 2 };
// Function to update inputs and submit the rating form
function updateInputsAndSubmit(button, retries = 0) {
const postElement = button.closest('.plhin');
if (!postElement) {
console.error('Could not find the post element associated with this button.');
return;
}
const score1 = document.querySelector('input#score1.px.z');
const score2 = document.querySelector('input#score2.px.z');
const score4 = document.querySelector('input#score4.px.z');
const usernameElement = postElement.querySelector('div.authi a.xw1');
const username = usernameElement ? usernameElement.innerText.trim() : '';
let rating = ratingLogic[username] || defaultRating;
if (score1 && score2 && score4) {
score1.value = rating.score1;
score2.value = rating.score2;
score4.value = rating.score4;
console.log(`Setting scores for user: ${username}`);
// Simulate form submission
const form = document.querySelector('form#rateform');
if (form) {
form.dispatchEvent(new Event('submit', { cancelable: true }));
} else {
console.error('Form not found.');
}
} else {
console.error('Score input fields are missing.');
if (retries < maxRetries) {
console.log(`Retrying to find score inputs... (${retries + 1}/${maxRetries})`);
setTimeout(() => updateInputsAndSubmit(button, retries + 1), retryDelay);
} else {
console.warn('Max retries exceeded for finding score input fields. Moving to next rate button.');
currentIndex.value++;
setTimeout(clickNextRateButton, 1000);
}
}
}
// Click next rate button and handle logic
function clickNextRateButton() {
const rateButtons = Array.from(document.querySelectorAll('a.rateb'));
if (currentIndex.value >= rateButtons.length) {
console.log('All replies have been rated.');
return;
}
const button = rateButtons[currentIndex.value];
const postElement = button.closest('.plhin');
if (shouldIgnoreMessage(postElement)) {
console.log(`Ignoring post ${currentIndex.value + 1}.`);
currentIndex.value++;
setTimeout(clickNextRateButton, 1000);
return;
}
updateInputsAndSubmit(button);
currentIndex.value++;
// Schedule the next iteration after a delay
setTimeout(clickNextRateButton, 1000);
}
// Function to decide if a message should be ignored
function shouldIgnoreMessage(postElement) {
const messageElement = postElement.querySelector('.t_f');
const messageHTML = messageElement ? messageElement.innerHTML.trim() : '';
const hasMeaningfulContent = messageHTML.length > 0; // Check for meaningful content
return !hasMeaningfulContent; // Ignore if no meaningful content
}
// Duplicate Title Detection
function checkForDuplicateTitles() {
const titles = Array.from(document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst'));
const titleCounts = {};
const duplicateTitles = [];
titles.forEach(titleElement => {
const title = titleElement.innerText.trim();
titleCounts[title] = (titleCounts[title] || 0) + 1;
if (titleCounts[title] > 1 && !duplicateTitles.includes(title)) {
duplicateTitles.push(title);
}
});
if (duplicateTitles.length > 0) {
alert('Warning: There are duplicate thread titles on this page!');
highlightDuplicates(duplicateTitles);
} else {
alert('No duplicate thread titles found.');
}
}
// Function to highlight duplicate titles
function highlightDuplicates(duplicateTitles) {
const titles = document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst');
titles.forEach(titleElement => {
if (duplicateTitles.includes(titleElement.innerText.trim())) {
titleElement.style.backgroundColor = 'yellow'; // Highlight duplicate titles
}
});
}
// Function to initiate auto-rating
function automateRating() {
currentIndex.value = 0; // Reset the index
clickNextRateButton(); // Start clicking buttons for auto-rating
}
// Function to add automation button to the UI
function addAutomationButton(container, buttonText, styles, buttonClass) {
if (container) {
const autoButton = document.createElement('button');
autoButton.innerText = buttonText;
autoButton.onclick = automateRating;
Object.assign(autoButton.style, styles);
autoButton.className = buttonClass;
container.appendChild(autoButton);
}
}
// Add custom button styles
const style = document.createElement('style');
style.textContent = `
.main-button {
background-color: #FE9510;
color: white;
border: none;
border-radius: 4px;
padding: 7px 10px;
font-size: 14.5px;
cursor: pointer;
margin: 0px;
transition: background-color 0.3s, color 0.3s;
}
.main-button:hover {
background-color: #E78F1B;
color: #FFF;
}
`;
document.head.appendChild(style);
// Adding automation buttons after the page loads
window.addEventListener('load', () => {
if (window.location.href.includes("thread") && document.querySelector('a.rateb')) {
// On pages with rating buttons, add auto-rate button
addAutomationButton(document.querySelector('div#pgt.pgs.cl'), '自動評分', {}, 'main-button');
}
// For duplicate title check, add button
addAutomationButton(document.querySelector('div.bm_c'), '檢查重複標題', {}, 'main-button'); // Button for duplicate check
});
})();
Key Features of the Combined Script:
Auto-Rating Functionality:
It retains the logic for automatically rating posts based on usernames.
Failure cases are handled, with retry logic in place if the input elements aren't found immediately.
Duplicate Title Detection:
Checks for duplicates in thread titles, using a specific selector matching your provided HTML.
Highlights duplicates and provides a user alert if any are found.
User Interface Buttons:
Two buttons are added to the UI: one for auto-rating and one for checking duplicate titles.
They are styled for consistency and visibility.
Testing the Combined Functionality:
Install this userscript in Tampermonkey or a similar userscript manager.
Navigate to pages on 141love.net where you expect to see ratings and thread titles.
Click the "自動評分" button for auto-rating and the "檢查重複標題" button to test duplicate detection.
Debugging:
If you face issues, check the console for any errors and add debugging statements (like console.log) to verify that elements are being selected correctly.
Verify that there are indeed duplicate thread titles present for the detection feature to function correctly.
If you need more modifications or run into any issues when testing this script, feel free to ask!
// ==UserScript==
// @name Duplicate Title Checker for 141love.net
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Check for duplicate thread titles on 141love.net
// @author Your Name
// @match https://141love.net/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Function to check for duplicate titles
function checkForDuplicateTitles() {
// Select the thread titles from the specified HTML structure
const titles = Array.from(document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst'));
const titleCounts = {};
const duplicateTitles = [];
titles.forEach(titleElement => {
const title = titleElement.innerText.trim(); // Get the title text and trim whitespace
titleCounts[title] = (titleCounts[title] || 0) + 1; // Count occurrences of each title
if (titleCounts[title] > 1 && !duplicateTitles.includes(title)) {
duplicateTitles.push(title); // Save duplicates if it appears more than once
}
});
if (duplicateTitles.length > 0) {
alert('Warning: There are duplicate thread titles on this page!');
highlightDuplicates(duplicateTitles); // Highlight duplicates
} else {
alert('No duplicate thread titles found.');
}
}
// Function to highlight duplicate titles
function highlightDuplicates(duplicateTitles) {
const titles = document.querySelectorAll('div.bm_c tbody[id^="normalthread_"] a.s.xst');
titles.forEach(titleElement => {
if (duplicateTitles.includes(titleElement.innerText.trim())) {
titleElement.style.backgroundColor = 'yellow'; // Highlight duplicate titles
}
});
}
// Function to add a duplicate check button to the UI
function addDuplicateCheckButton(container) {
if (container) {
const checkButton = document.createElement('button');
checkButton.innerText = '檢查重複標題'; // Check for duplicate titles
checkButton.onclick = checkForDuplicateTitles; // Attach function to button
// Add button styles
checkButton.style.backgroundColor = "#FE9510";
checkButton.style.color = "white";
checkButton.style.border = "none";
checkButton.style.borderRadius = "4px";
checkButton.style.padding = "7px 10px";
checkButton.style.fontSize = "14.5px";
checkButton.style.cursor = "pointer";
checkButton.style.margin = "10px"; // Add margin for better spacing
container.appendChild(checkButton); // Add button to the designated container
}
}
// Adding the duplicate check button after the page loads
window.addEventListener('load', () => {
const bmContainer = document.querySelector('div.bm_c'); // Find the main container for threads
if (bmContainer) {
addDuplicateCheckButton(bmContainer); // Add the button to the container found
} else {
console.log('Not a valid page for duplicate checking. Button will not be added.');
}
});
})();
Key Features of the Script:
Duplicate Title Detection:
The script checks for duplicate thread titles specifically by selecting the relevant elements based on your provided HTML structure.
Highlighting Duplicates:
It highlights duplicates in yellow for easy identification.
User Interface Enhancement:
A single button titled "檢查重複標題" is added to the UI, which triggers the duplicate title check.
How to Use This Script:
Install this script in Tampermonkey or another userscript manager.
Navigate to 141love.net pages that display thread titles.
Click the "檢查重複標題" button, and any duplicate titles will be highlighted.
If there are still issues or specific requirements that need tuning, please let me know!
Explanation of the Script:
Automatic Duplicate Checking:
The script checks for duplicate titles as soon as the div.bm_c container is detected after the page loads.
Highlighting Duplicates:
Duplicate titles are highlighted in yellow and made bold for clear visibility.
Alerts:
An alert is issued to notify users about duplicates on the page.
How to Use This Script:
Install this script in Tampermonkey or a similar userscript manager.
Visit any page on 141love.net that displays thread titles.
The script will automatically check for duplicates once the relevant content is loaded, displaying alerts and highlighting duplicates as necessary.
This version streamlines your requirement without any additional buttons, ensuring a seamless experience. If you need further adjustments, let me know!