Move banned check api request to only run when someone tries to promote the thread rather on every page load, reducing traffic.
193 lines
7.4 KiB
JavaScript
193 lines
7.4 KiB
JavaScript
// ==UserScript==
|
|
// @name Promote Current Time
|
|
// @namespace http://tampermonkey.net/
|
|
// @version 0.6.2
|
|
// @description Enter the current time for promotion.
|
|
// @author Gameil
|
|
// @match https://f95zone.to/threads/*/
|
|
// @icon https://www.google.com/s2/favicons?domain=f95zone.to
|
|
// @grant GM_xmlhttpRequest
|
|
// @updateURL https://git.zonies.xyz/Ryahn/F95Zone-Scripts/raw/branch/main/quick-promoter.js
|
|
// @downloadURL https://git.zonies.xyz/Ryahn/F95Zone-Scripts/raw/branch/main/quick-promoter.js
|
|
// ==/UserScript==
|
|
|
|
(async function () {
|
|
let token = localStorage.getItem('api-token');
|
|
|
|
if (!token) {
|
|
token = prompt('Please enter API token from Rule7 App');
|
|
localStorage.setItem('api-token', token);
|
|
}
|
|
|
|
var devName = '';
|
|
let devBanned = false;
|
|
|
|
// 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) {
|
|
const dev_name = game_name.slice(dev_name_index);
|
|
const dev_with_link = document.createElement('a');
|
|
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.style.color = 'inherit';
|
|
game_name_ele.textContent = game_name.slice(0, dev_name_index);
|
|
title.appendChild(dev_with_link);
|
|
}
|
|
}
|
|
|
|
// Promote time button
|
|
const menuLinkBtn = document.querySelectorAll(".menu-linkRow");
|
|
let promoBtn, currentBtn;
|
|
menuLinkBtn.forEach((el) => {
|
|
if (el.innerText == "Promote Thread") {
|
|
promoBtn = el;
|
|
}
|
|
});
|
|
if (promoBtn) {
|
|
promoBtn.addEventListener("click", async () => {
|
|
console.log("Clicked Promo Button");
|
|
if (!currentBtn) {
|
|
createBtn();
|
|
setTimeout(addBtn, 300);
|
|
|
|
// Checking Dev banned status using api
|
|
const searchThreadId = document.URL.split('/')[4].split('.')[1];
|
|
console.time('Check Dev Banned');
|
|
devBanned = await checkDevBanned(searchThreadId, token);
|
|
console.timeEnd('Check Dev Banned');
|
|
}
|
|
});
|
|
}
|
|
|
|
function createBtn() {
|
|
// Creating enter button
|
|
currentBtn = document.createElement("button");
|
|
currentBtn.type = "button";
|
|
currentBtn.title = "Enter Current time";
|
|
currentBtn.classList.add("button");
|
|
currentBtn.style.cssText = "padding: 0; left: 1em; position: relative;";
|
|
currentBtn.innerHTML = `
|
|
<span class="fa-stack fa-lg">
|
|
<i class="fad fa-reply fa-stack-2x"></i>
|
|
<i class="fad fa-clock fa-stack" style="top: .4em; left: -0.4em; color: white; font-size: 1.2em;"></i>
|
|
</span>
|
|
`;
|
|
}
|
|
|
|
function addBtn() {
|
|
const inputGroup = document.querySelector(
|
|
".inputGroup--date.inputGroup--joined.inputDate"
|
|
);
|
|
if (!inputGroup) {
|
|
console.log("Unable to add button, trying again in 500ms");
|
|
setTimeout(addBtn, 500);
|
|
return;
|
|
}
|
|
|
|
const inputBlock = inputGroup.parentNode;
|
|
inputBlock.appendChild(currentBtn);
|
|
|
|
currentBtn.addEventListener("click", () => {
|
|
const dateInput = document.querySelector('[name="promote_time_ymd"]');
|
|
const hhInput = document.querySelector('[name="promote_time_hh"]');
|
|
const mmInput = document.querySelector('[name="promote_time_mm"]');
|
|
|
|
const lastPromoteTime = new Date(
|
|
`${dateInput.value}T${hhInput.value}:${mmInput.value}:00`
|
|
);
|
|
const currentTime = new Date();
|
|
const month = currentTime.getMonth() + 1;
|
|
const date = `${currentTime.getFullYear()}-${month}-${currentTime.getDate()}`;
|
|
const hour = currentTime.getHours();
|
|
const minute = currentTime.getMinutes();
|
|
|
|
const timeDiff = currentTime.getTime() - lastPromoteTime.getTime();
|
|
|
|
const messageBlock = document.querySelector(".formRow-explain");
|
|
|
|
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");
|
|
setTimeout(() => {
|
|
messageBlock.parentNode.parentNode.parentElement.classList.remove(
|
|
"shake"
|
|
);
|
|
}, 500);
|
|
} else if (timeDiff < 14 * 24 * 60 * 60 * 1000) {
|
|
messageBlock.textContent =
|
|
"Warning: This thread was promoted less than two weeks ago.";
|
|
messageBlock.style.color = "yellow";
|
|
messageBlock.style.fontSizeAdjust = 0.6;
|
|
messageBlock.parentNode.parentNode.parentElement.classList.add("shake");
|
|
setTimeout(() => {
|
|
messageBlock.parentNode.parentNode.parentElement.classList.remove(
|
|
"shake"
|
|
);
|
|
}, 500);
|
|
} else {
|
|
dateInput.value = date;
|
|
hhInput.options[hour].selected = true;
|
|
mmInput.options[minute].selected = true;
|
|
messageBlock.textContent =
|
|
"Entered Current Time. Click Save to Promote.";
|
|
messageBlock.style.color = "green";
|
|
}
|
|
});
|
|
|
|
let style = document.createElement("style");
|
|
style.innerHTML = `
|
|
.shake {
|
|
animation: shake 0.3s;
|
|
}
|
|
@keyframes shake {
|
|
0% { transform: translate(0, 0); }
|
|
20% { transform: translate(-10px, 0); }
|
|
40% { transform: translate(10px, 0); }
|
|
60% { transform: translate(-10px, 0); }
|
|
80% { transform: translate(10px, 0); }
|
|
100% { transform: translate(0, 0); }
|
|
}
|
|
`;
|
|
document.head.appendChild(style);
|
|
}
|
|
})(); |