Fixed issue where you couldn't promote any thread due to saying Dev is banned from promotion
191 lines
7.4 KiB
JavaScript
191 lines
7.4 KiB
JavaScript
// ==UserScript==
|
|
// @name Promote Current Time
|
|
// @namespace http://tampermonkey.net/
|
|
// @version 0.6.1
|
|
// @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==
|
|
|
|
(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 = '';
|
|
|
|
//search dev name
|
|
const title = document.getElementsByClassName('p-title-value')[0]
|
|
let devBanned = false;
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
});
|
|
}
|
|
|
|
//promote time button add
|
|
const menuLinkBtn = document.querySelectorAll(".menu-linkRow");
|
|
let promoBtn, currentBtn;
|
|
menuLinkBtn.forEach((el) => {
|
|
if (el.innerText == "Promote Thread") {
|
|
promoBtn = el;
|
|
}
|
|
});
|
|
if (promoBtn) {
|
|
promoBtn.addEventListener("click", () => {
|
|
console.log("Clicked Promo Button");
|
|
if (!currentBtn) {
|
|
createBtn();
|
|
setTimeout(addBtn, 300);
|
|
}
|
|
});
|
|
}
|
|
|
|
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){ //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.";
|
|
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) { //recent promotion check
|
|
|
|
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);
|
|
}
|
|
})(); |