108 lines
3.7 KiB
JavaScript
108 lines
3.7 KiB
JavaScript
// ==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;
|
|
}
|
|
}
|
|
|
|
})(); |