From 7593c6620df7817f4b7df7fc1b4cda4e31504326 Mon Sep 17 00:00:00 2001 From: Ryahn Date: Thu, 21 Nov 2024 18:31:46 -0600 Subject: [PATCH] updates and release Added better checking and release of r7 checker --- Changelog.md | 13 ++++-- quick-promoter.js | 105 ++++++++++++++++++++++---------------------- rule7-notify.js | 108 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+), 55 deletions(-) create mode 100644 rule7-notify.js diff --git a/Changelog.md b/Changelog.md index 3cfaf44..c467851 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,10 @@ -## 0.6.1 -### Quick Promoter -- Fixed issue where you couldn't promote any thread due to saying Dev is banned from promotion \ No newline at end of file + +## Quick Promoter +### 0.6.1 +- Fixed issue where you couldn't promote any thread due to saying Dev is banned from promotion +### 0.6.2 +- Added better checking for banned promotion check + +## Rule7 Notify +### 0.1.0 +- Initial release diff --git a/quick-promoter.js b/quick-promoter.js index 28de3b5..bc51af8 100644 --- a/quick-promoter.js +++ b/quick-promoter.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Promote Current Time // @namespace http://tampermonkey.net/ -// @version 0.6.1 +// @version 0.6.2 // @description Enter the current time for promotion. // @author Gameil // @match https://f95zone.to/threads/*/ @@ -11,7 +11,7 @@ // @downloadURL https://git.zonies.xyz/Ryahn/F95Zone-Scripts/raw/branch/main/quick-promoter.js // ==/UserScript== -(function () { +(async function () { let token = localStorage.getItem('api-token'); if (!token) { @@ -20,57 +20,63 @@ } var devName = ''; - - //search dev name - const title = document.getElementsByClassName('p-title-value')[0] let devBanned = false; - if(title){ + + // Asynchronous function to check if developer is banned + async function checkDevBanned(threadId, token) { + try { + const response = await new Promise((resolve, reject) => { + GM_xmlhttpRequest({ + method: 'GET', + url: `https://rule7.zonies.xyz/api/v1/promotion?thread_id=${threadId}`, + headers: { + 'Authorization': `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + onload: resolve, + onerror: reject, + }); + }); + + if (response.status === 200) { + const data = JSON.parse(response.responseText); + console.log('API Response:', data); + return Array.isArray(data) && data.length !== 0; // true if banned + } else { + console.error('API Request failed:', response.status, response.statusText); + return false; + } + } catch (error) { + console.error('Request Error:', error); + return false; + } + } + + const title = document.getElementsByClassName('p-title-value')[0]; + + if (title) { const game_name_ele = title.lastChild; const game_name = game_name_ele.textContent; const dev_name_index = game_name.lastIndexOf('['); - if(dev_name_index !== -1) { + if (dev_name_index !== -1) { const dev_name = game_name.slice(dev_name_index); const dev_with_link = document.createElement('a'); - devName = dev_name.slice(1,-1); + devName = dev_name.slice(1, -1); dev_with_link.textContent = dev_name; - dev_with_link.href = 'https://f95zone.to/sam/latest_alpha/#/cat=games/page=1/creator='+devName; + dev_with_link.href = 'https://f95zone.to/sam/latest_alpha/#/cat=games/page=1/creator=' + devName; dev_with_link.style.color = 'inherit'; game_name_ele.textContent = game_name.slice(0, dev_name_index); title.appendChild(dev_with_link); } - const pattern = /^(.+?) \[(.+?)\](?: ?\[(.+?)\])?$/ - const titleData = game_name.match(pattern); - const searchDevName = titleData[3] || 'NONE'; - const searchthreadId = document.URL.split('/')[4].split('.')[1]; - - GM_xmlhttpRequest({ - method: 'GET', // Change to 'POST' or other HTTP methods as needed - url: 'https://rule7.zonies.xyz/api/v1/promotion?thread_id=' + searchthreadId, - headers: { - 'Authorization': `Bearer ${token}`, - 'Content-Type': 'application/json', // Include if your API requires it - }, - onload: function(response) { - if (response.status === 200) { - const data = JSON.parse(response.responseText); - if (Array.isArray(data) && data.length !== 0) { - devBanned = true; - } - // Handle successful response here - } else { - console.error('API Request failed:', response.status, response.statusText); - // Handle error here - } - }, - onerror: function(error) { - console.error('Request Error:', error); - } - }); + const searchThreadId = document.URL.split('/')[4].split('.')[1]; + console.time('Check Dev Banned'); + devBanned = await checkDevBanned(searchThreadId, token); + console.timeEnd('Check Dev Banned'); } - //promote time button add + // Promote time button const menuLinkBtn = document.querySelectorAll(".menu-linkRow"); let promoBtn, currentBtn; menuLinkBtn.forEach((el) => { @@ -89,7 +95,7 @@ } function createBtn() { - //creating enter button + // Creating enter button currentBtn = document.createElement("button"); currentBtn.type = "button"; currentBtn.title = "Enter Current time"; @@ -121,7 +127,7 @@ const hhInput = document.querySelector('[name="promote_time_hh"]'); const mmInput = document.querySelector('[name="promote_time_mm"]'); - const lastpromoteTime = new Date( + const lastPromoteTime = new Date( `${dateInput.value}T${hhInput.value}:${mmInput.value}:00` ); const currentTime = new Date(); @@ -130,17 +136,14 @@ const hour = currentTime.getHours(); const minute = currentTime.getMinutes(); - const timeDiff = currentTime.getTime() - lastpromoteTime.getTime(); + const timeDiff = currentTime.getTime() - lastPromoteTime.getTime(); const messageBlock = document.querySelector(".formRow-explain"); - if (timeDiff < 60 * 1000){ //do nothing if time was entered recently (less than 60 seconds) - return; - } - - else if (devBanned) { //banned from promo check - messageBlock.textContent = - "The developer is banned from promotion."; + if (timeDiff < 60 * 1000) { + return; // Do nothing if time was entered recently (less than 60 seconds) + } else if (devBanned) { + messageBlock.textContent = "The developer is banned from promotion."; messageBlock.style.color = "Red"; messageBlock.style.fontSizeAdjust = 0.6; messageBlock.parentNode.parentNode.parentElement.classList.add("shake"); @@ -149,10 +152,7 @@ "shake" ); }, 500); - } - - else if (timeDiff < 14 * 24 * 60 * 60 * 1000) { //recent promotion check - + } else if (timeDiff < 14 * 24 * 60 * 60 * 1000) { messageBlock.textContent = "Warning: This thread was promoted less than two weeks ago."; messageBlock.style.color = "yellow"; @@ -172,6 +172,7 @@ messageBlock.style.color = "green"; } }); + let style = document.createElement("style"); style.innerHTML = ` .shake { diff --git a/rule7-notify.js b/rule7-notify.js new file mode 100644 index 0000000..b1c9d08 --- /dev/null +++ b/rule7-notify.js @@ -0,0 +1,108 @@ +// ==UserScript== +// @name Rule7 Notify +// @namespace http://tampermonkey.net/ +// @version 0.1.0 +// @description Notify when a new Rule7 game is found +// @author Ryahn +// @match https://f95zone.to/threads/* +// @icon https://www.google.com/s2/favicons?sz=64&domain=f95zone.to +// @grant GM_xmlhttpRequest +// @updateURL https://git.zonies.xyz/Ryahn/F95Zone-Scripts/raw/branch/main/rule7-notify.js +// @downloadURL https://git.zonies.xyz/Ryahn/F95Zone-Scripts/raw/branch/main/rule7-notify.js +// ==/UserScript== + +(async function() { + 'use strict'; + let token = localStorage.getItem('r7-notify-api-token'); + + if (!token || token === '' || token === null) { + token = prompt('Please enter API token from Rule7 App'); + localStorage.setItem('r7-notify-api-token', token); + } + + const title = document.getElementsByClassName('p-title-value')[0]; + let game_name, dev_name; + if(title){ + const game_name_ele = title.lastChild; + game_name = game_name_ele.textContent; + } + const pattern = /^(.+?) \[(.+?)\](?: ?\[(.+?)\])?$/ + const titleData = game_name.match(pattern); + + if (!titleData[1]) { + return console.log('[ERR] Game name cannot be parsed'); + } else if (titleData[3]) { + dev_name = titleData[3]; + } else { + dev_name = 'NONE'; + } + + game_name = titleData[1]; + + const isGameBanned = await checkGameBanned(game_name, token); + const isDevBanned = await checkDevBanned(dev_name, token); + + if (isGameBanned || isDevBanned) { + console.log(`[ERR] Game or Dev is banned`); + } + + async function checkGameBanned(game, token) { + try { + const response = await new Promise((resolve, reject) => { + GM_xmlhttpRequest({ + method: 'GET', + url: `https://rule7.zonies.xyz/api/v1/games?game_name=${game}`, + headers: { + 'Authorization': `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + onload: resolve, + onerror: reject, + }); + }); + + if (response.status === 200) { + const data = JSON.parse(response.responseText); + const isBanned = data.some(item => item.game_name === game); + return isBanned; + } else { + console.error('API Request failed:', response.status, response.statusText); + return false; + } + } catch (error) { + console.error('Request Error:', error); + return false; + } + } + + async function checkDevBanned(dev, token) { + if (dev === 'NONE') return false; + try { + const response = await new Promise((resolve, reject) => { + GM_xmlhttpRequest({ + method: 'GET', + url: `https://rule7.zonies.xyz/api/v1/games?dev_name=${dev}`, + headers: { + 'Authorization': `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + onload: resolve, + onerror: reject, + }); + }); + + if (response.status === 200) { + const data = JSON.parse(response.responseText); + const isBanned = data.some(item => item.author === dev); + return isBanned; + } else { + console.error('API Request failed:', response.status, response.statusText); + return false; + } + } catch (error) { + console.error('Request Error:', error); + return false; + } + } + +})(); \ No newline at end of file