Таймеры для гильдии охотников и наёмников
当前为
// ==UserScript==
// @name [HWM] GuildTimersOnMain
// @namespace [HWM] GuildTimersOnMain
// @version 0.1.0
// @description Таймеры для гильдии охотников и наёмников
// @author Komdosh
// @include http*://*.heroeswm.ru/home.php*
// @grant none
// @license MIT
// ==/UserScript==
var GUILDS_INFO = 'GUILDS_INFO';
var guildsInfoDiv = document.createElement('div');
guildsInfoDiv.className += "home_container_block";
guildsInfoDiv.style="align-items: left;"
var guildsInfoHeader = document.createElement('div');
guildsInfoHeader.className += "global_container_block_header global_a_hover";
guildsInfoHeader.innerHTML = 'Таймеры';
guildsInfoDiv.append(guildsInfoHeader);
var guildsInfoContentDiv = document.createElement('div');
guildsInfoContentDiv.className += "home_inside_margins global_a_hover";
guildsInfoDiv.append(guildsInfoContentDiv);
var workerGuild = document.querySelector(".home_work_block");
workerGuild.after(guildsInfoDiv);
var loading = document.createElement('span');
loading.innerText = 'Данные обновляются...';
guildsInfoContentDiv.append(loading);
setTimeout(()=>requestHunterInfo(), 200);
setTimeout(()=>requestMercenaryInfo(), 700);
//***************************************************************************
function requestHunterInfo()
{
var xhr = new XMLHttpRequest();
xhr.open('GET', encodeURI("/map.php"));
xhr.overrideMimeType('text/xml; charset=windows-1251');
xhr.onload = function(){
if (xhr.status === 200)
{
var div = document.createElement( 'div' );
div.id = 'kom-hunter';
div.style.display = 'none';
div.innerHTML = xhr.responseText;
document.getElementsByTagName('body')[0].appendChild( div );
var respDoc = document.getElementsByTagName('body')[0].lastChild;
var script = document.querySelector('#map_right_block_inside').getElementsByTagName('script')[0];
var hunterTimerDiv = document.createElement('div');
hunterTimerDiv.id = 'next_ht';
hunterTimerDiv.append(document.createElement( 'br' ));
guildsInfoContentDiv.append(hunterTimerDiv);
var scriptDeltaText = script.text.match(/Delta2 = (\d+)/);
if(loading != null){
loading.remove();
}
if(scriptDeltaText == null){
hunterTimerDiv.innerHTML = 'ГО: <a href="map.php" style="text-decoration:underline">Новая охота</a>';
} else {
var delta = scriptDeltaText[1];
initHuntersTimer(delta, hunterTimerDiv);
}
respDoc.remove();
}
else {
console.log('Request failed. Returned status of ' + xhr.status);
}
};
xhr.send();
}
//***************************************************************************
function requestMercenaryInfo()
{
var xhr = new XMLHttpRequest();
xhr.open('GET', encodeURI("/mercenary_guild.php"));
xhr.overrideMimeType('text/xml; charset=windows-1251');
xhr.onload = function(){
if (xhr.status === 200)
{
var div = document.createElement( 'div' );
div.id = 'kom-mercenary';
div.style.display = 'none';
div.innerHTML = xhr.responseText;
document.getElementsByTagName('body')[0].appendChild( div );
var respDoc = document.getElementsByTagName('body')[0].lastChild;
var taskMessageDiv = respDoc.querySelector('table:not([align="center"])').querySelector('table:not([align="center"], [class="wbwhite"])');
var mercenaryTimerDiv = document.createElement('div');
mercenaryTimerDiv.id = 'mercenary';
if(loading != null){
loading.remove();
}
if(taskMessageDiv == null){
hunterTimerDiv.innerHTML = 'ГН: <a href="mercenary_guild.php" style="text-decoration:underline">Новое задание</a>';
}else{
var taskMessage = taskMessageDiv.querySelector('td').innerText;
mercenaryTimerDiv.innerHTML = 'ГН: Задание будет доступно через:' + taskMessage.split('\u0447\u0435\u0440\u0435\u0437')[1]; //через
guildsInfoContentDiv.append(mercenaryTimerDiv);
}
respDoc.remove();
}
else {
console.log('Request failed. Returned status of ' + xhr.status);
}
};
xhr.send();
}
//***************************************************************************
function formatFinishedTime(finishTime){
var diff = finishTime - Date.now();
var diffDays = Math.floor(diff / 86400000); // days
var diffHrs = Math.floor((diff % 86400000) / 3600000); // hours
var diffMins = Math.round(((diff % 86400000) % 3600000) / 60000); // minutes
var dateString = '';
if(diffDays > 0){
dateString += diffDays + ' \u0434. ';
}
if(diffHrs > 0){
dateString += diffHrs + ' \u0447. ';
}
if(diffMins > 0){
dateString += diffMins + ' \u043C\u0438\u043D.';
}
return dateString;
}
//***************************************************************************
function parseGuildDateTime(dateString){
dateString = dateString.split(' ');
var datef = dateString[0].split('-');
var date = new Date(datef[1]+'-'+datef[0]+'-'+(new Date().getFullYear()));
var time = dateString[1].split(':');
date.setHours(time[0], time[1], 0);
return date;
}
//***************************************************************************
function setWithExpiry(key, value, expirationTime) {
const item = {
value: value,
expiry: expirationTime,
}
localStorage.setItem(key, JSON.stringify(item))
}
//***************************************************************************
function getWithExpiry(key) {
const itemStr = localStorage.getItem(key)
// if the item doesn't exist, return null
if (!itemStr) {
return null
}
const item = JSON.parse(itemStr)
const now = new Date()
// compare the expiry time of the item with the current time
if (now.getTime() > item.expiry) {
// If the item is expired, delete the item from storage
// and return null
localStorage.removeItem(key)
return null
}
return item.value
}
//**
function initHuntersTimer(Delta2, hunterTimerDiv){
function print_hunt_time(t)
{
if (t < 0) t = 0;
var min = Math.floor(t / 60);
var sec = t % 60;
var s = '';
if (min) s = min+' '+ 'мин. ';
s = s + sec + ' ' + 'с. ';
hunterTimerDiv.innerHTML= 'ГО: Охота будет доступна через ' + s;
}
var Refresh2 = ()=>{
if (Timer2>=0) clearTimeout(Timer2);
Delta2 = Delta2 - 1;
print_hunt_time(Delta2);
if (Delta2 >= 0) Timer2=setTimeout(Refresh2,1000);
if (Delta2 < 0) window.location='/map.php'
}
var Timer2 = setTimeout(Refresh2, 1000);
print_hunt_time(Delta2);
}
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址