// ==UserScript==
// @name hwmNightMode
// @author Мифист, Tamozhnya1
// @namespace Tamozhnya1
// @description Ночная тема
// @version 11.5
// @include https://*heroeswm.ru/*
// @include https://*lordswm.com/*
// @exclude */chat*
// @exclude */war*
// @exclude */cgame*
// @exclude /\/quest_(?!journal)/
// @exclude /\.(ru|com)\/$/
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @noframes
// @license MIT
// ==/UserScript==
const playerIdMatch = document.cookie.match(/pl_id=(\d+)/);
const PlayerId = playerIdMatch ? playerIdMatch[1] : "";
const lang = document.documentElement.lang || (location.hostname == "www.lordswm.com" ? "en" : "ru");
const isEn = lang == "en";
const win = window.wrappedJSObject || unsafeWindow;
const isHeartOnPage = (document.querySelector("canvas#heart") || document.querySelector("div#heart_js_mobile")) ? true : false;
const isMooving = location.pathname == '/map.php' && !document.getElementById("map_right_block");
const isNewInterface = document.querySelector("div#hwm_header") ? true : false;
const isMobileInterface = document.querySelector("div#btnMenuGlobal") ? true : false;
const isMobileDevice = mobileCheck(); // Там нет мышки
const isNewPersonPage = document.querySelector("div#hwm_no_zoom") ? true : false;
fetch.get = (url) => fetch({ url });
fetch.post = (url, data) => fetch({ url, method: 'POST', body: data });
if(!PlayerId) {
return;
}
const nightStyle = parseNode(`<style>
:root {
overflow-y: auto;
}
:root,
:root > body {
color: #ccc;
background-color: #222;
border-color: #888;
}
:root > body * {
border-color: #888;
}
:root .wbwhite,
:root .wblight2 {
background-color: #1d1d1d;
}
:root .wblight {
background-color: #2d2d2d;
}
:root a,
:root td,
:root .txt {
color: #ccc;
}
button,
input[type="button"],
input[type="submit"] {
cursor: pointer;
}
:root input,
:root button {
border-color: initial;
}
:root button:hover,
:root input[type="button"]:hover:root input[type="submit"]:hover {
background-color: #fff;
}
:root :disabled {
color: #666 !important;
background-color: #bbb !important;
cursor: default;
}
:root b,
:root h1,
:root h2,
:root h3,
:root h4,
:root h5,
:root h6,
:root strong {
color: #d0bda6;
}
:root font[color] * {
color: inherit;
}
:root a[href],
:root a[href] > *,
:root b > a[href] {
color: #c9b087;
}
:root a[href]:hover,
:root a[href]:hover *,
:root a[href]:hover + font[color] {
color: #da472d !important;
}
:root font[color="black"],
:root font[color="000000"] {
color: #999;
}
:root font[color="gray"],
:root font[color="#7D7D7D"] {
color: #999;
}
:root font[color="red"],
:root font[color="#CC1100"],
:root font[color="ff0000"] {
color: #d03535;
}
:root font[color="green"],
:root font[color="00ff00"] {
color: #4f9a68;
}
:root font[color="blue"] {
color: #3171a3;
}
:root font[color="purple"] {
color: #ab3cab;
}
font[style$="color:#696156"] {
color: #c9b087 !important;
}
#main_top_table table[width="970"] {
background-color: inherit !important;
}
#main_top_table img,
#main_top_table td[style*="/right_big.jpg"],
#main_top_table td[style*="/line/lbkg.jpg"],
#main_top_table td[style*="/bkgbot.jpg"],
#main_top_table td[style*="/bkgtop.jpg"] {
-webkit-filter: invert(1) grayscale(1) contrast(1.05);
filter: invert(1) grayscale(1) contrast(1.05);
}
#main_top_table td[style*="/t_bot_bkg.jpg"],
#main_top_table td[style*="/t_top_bkg.jpg"],
#main_top_table td[width="9"] {
-webkit-filter: sepia(1) grayscale(0.5);
filter: sepia(1) grayscale(0.5);
}
#main_top_table img.rs,
#main_top_table img[src$="/res_line_botc.jpg"],
#main_top_table img[src$="/res_line_topc.jpg"],
#main_top_table table[width="580"] img {
-webkit-filter: none;
filter: none;
}
#main_top_table td[style$="/top/bkg2.jpg);"] {
background-image: none !important;
background-color: #333 !important;
}
#main_top_table td[height="17"] {
color: #222;
}
#main_top_table td[height="26"][width="88"]:nth-child(3) {
border-right: 2px solid tan;
}
#main_top_table td[height="26"][width="88"]:nth-child(5) {
border-left: 2px solid tan;
}
#breadcrumbs a {
color: #ccc !important;
}
#breadcrumbs a[style$="#ff0000;"] > b {
color: #ea9f2f;
}
#breadcrumbs a:hover,
#breadcrumbs a:hover blink {
color: #c9b087 !important;
}
#breadcrumbs li.subnav:hover b {
color: #dadada !important;
}
#breadcrumbs hr {
border: none;
height: 1px;
background-color: #999;
}
#breadcrumbs blink {
color: #c9b087;
}
.cre_mon_parent [valign="middle"] {
color: #eee;
background: #333 !important;
outline: 1px solid gray;
}
#add_now_count {
color: #c9b087;
}
tr[bgcolor],
td[bgcolor] {
background-color: inherit;
}
tr[bgcolor="#ffffff"],
td[bgcolor="#ffffff"] {
background-color: #222;
}
tr[bgcolor="#eeeeee"],
td[bgcolor="#eeeeee"] {
background-color: #272727;
}
tr[bgcolor="#dddddd"] {
background-color: #404040;
}
td.wb[bgcolor="#cbc9fb"] {
background-color: #263c46;
}
img[name="imgcode"] {
-webkit-filter: invert(0.8);
filter: invert(0.8);
}
img[src$="male.gif"] {
-webkit-filter: invert(0.86);
filter: invert(0.86);
}
img[src$="/horse_gif.gif"],
img[src$="/star0t.gif"],
img[src$="/star1t.gif"],
img[src$="/star12t.gif"],
img[src$="/speed_hunt.png"],
img[src$="/galka.jpg"],
img[src$="/zvezda.png"],
img[src$="/zvezda_empty.png"],
img[src$="/blood_rage.jpg"],
img[src*="/magic/l"],
img[src*="/pvp_"] {
-webkit-filter: invert(0.9) sepia(1);
filter: invert(0.9) sepia(1);
}
[data-page="clan_info"] img[src$="line.gif"],
img[src*="/map/nl"] {
border-radius: 50%;
}
:root .sweet-overlay {
background-color: rgba(27, 27, 27, 0.6);
}
:root .sweet-alert {
background-color: #444;
border: 2px solid #777;
-webkit-user-select: none;
user-select: none;
}
:root .sweet-alert:not(.showSweetAlert) {
opacity: 0 !important;
}
:root .sweet-alert,
:root .sweet-alert * {
transition: none;
animation: none;
}
:root .sweet-alert p {
color: #aaa;
}
:root .sweet-alert button {
background-color: #607d8b !important;
box-shadow: none !important;
}
:root .sweet-alert button.confirm {
background-color: #795548 !important;
}
:root .sweet-alert button:hover {
-webkit-filter: brightness(120%);
filter: brightness(120%);
}
#lbOverlay,
#lbCenter,
#lbBottomContainer {
z-index: 100;
} /* ------------------------------------------- */ /* auction */
[data-page="auction"] td[bgcolor="#9ADEED"] {
background-color: #58423a;
}
[data-page="auction"] td[bgcolor="#A09CEA"] {
background-color: #395f61;
} /* forum */
.forum.c_darker * {
border-color: #888;
}
.forum.c_darker tr {
background-color: #222;
}
.forum.c_darker tr > td[bgcolor="#F5F3EA"],
.forum.c_darker tr.second {
background-color: #333;
}
.forum.c_darker th {
background-color: #555;
}
.forum.c_darker td {
color: #ccc !important;
background-image: none;
outline: 1px solid #444;
outline-offset: -2px;
}
.forum.c_darker td[style$="image: none"] {
outline: none;
}
.forum.c_darker tr > td[colspan] {
background-color: #6d6d6d;
}
.forum.c_darker tr.message_footer td {
color: #888 !important;
background-color: #333;
border: none;
}
.forum.c_darker td a[href] {
color: #c9b087;
}
.forum.c_darker a[href^="forum_thread"] > img {
-webkit-filter: invert(0.9) sepia(0.6);
filter: invert(0.9) sepia(0.6);
}
.forum.c_darker span[style*="background-color: #C1CDCE"] {
background-color: #444 !important;
}
.forum.c_darker font[style*="color:#696156"] {
color: #aaa !important;
}
.forum.c_darker .fsm,
.forum.c_darker .forumt {
color: inherit;
}
#nm_txta {
background-color: #ddd;
}
[data-page="forum_thread"] .forum tr:hover {
background-color: #5d4942 !important;
}
[data-page="forum_thread"] .forum a[href]:hover {
color: #f8be66 !important;
} /* roulette */
[data-page*="roul"] td.wblight {
background-color: #555;
}
[data-page*="roul"] td.wb2 {
background-color: #795548;
} /* tavern */
td[style*="/taverna_bkg.jpg"],
td[style*="/taverna_bkg.jpg"] td[class] {
background-image: none !important;
border-color: #666;
}
td[style*="/taverna_bkg.jpg"] td.tlight {
background-color: #333;
}
td[style*="/taverna_bkg.jpg"] td.twhite {
background-color: #464646;
} /* events */
.Global [class^="TextBlockContent"] {
background: url("https://dcdn3.heroeswm.ru/i/naym_event_rogues/corner4_lt.png") no-repeat top left, url("https://dcdn3.heroeswm.ru/i/naym_event_rogues/corner4_rt.png") no-repeat top right,
url("https://dcdn3.heroeswm.ru/i/naym_event_rogues/corner4_lb.png") no-repeat bottom left, url("https://dcdn3.heroeswm.ru/i/naym_event_rogues/corner4_rb.png") no-repeat bottom right,
url("https://dcdn3.heroeswm.ru/i/naym_event_rogues/winChatDesktop_border_t.png") top left repeat-x, url("https://dcdn3.heroeswm.ru/i/naym_event_rogues/winChatDesktop_border_b.png") bottom left repeat-x,
url("https://dcdn3.heroeswm.ru/i/naym_event_rogues/winChatDesktop_border_l.png") top left repeat-y, url("https://dcdn3.heroeswm.ru/i/naym_event_rogues/winChatDesktop_border_r.png") top right repeat-y;
background-size: 2.2%, 2.2%, 2.2%, 2.2%, auto, auto, auto, auto, auto;
background-color: rgba(35, 35, 35, 0.95);
}
.Global .cre_mon_image1[style],
.Global td[width="60"] {
background-color: #333 !important;
} /* naym_event_set */
[data-page="naym_event_set"] td.wbwhite[width="100%"][align="center"] td[width="60"] {
background-color: inherit !important;
} /* map */
#jsmap {
outline: 2px solid #444;
}
.no_touch_selection > div:first-child {
background-image: linear-gradient(to right, transparent, #1d1d1d, #1d1d1d) !important;
}
.ohota_block,
#map_right_block .wbwhite[style^="border"] {
border-color: inherit !important;
}
[data-page="map"] .ntooltiptext {
color: #333;
background-color: rgba(255, 255, 255, 0.85);
border-color: #222 !important;
box-shadow: 0 0 10px #555;
} /* object-info */
:root .getjob_block {
color: inherit;
background-color: #333;
}
:root .getjob_capcha {
filter: invert(0.9);
}
:root #code {
background: #222;
color: inherit;
box-shadow: 0 0 3px;
} /* army_info */
.army_info {
background-color: #333;
background-image: none;
background-image: linear-gradient(#555, #111);
}
.scroll_content_half {
color: inherit;
}
.scroll_content_half div {
color: #d6b47d;
}
.army_info_skills {
text-align: left;
}
.army_info_skills > div {
color: #ccc;
}
.army_info_skills [id^="skill_name"] {
color: #bbb;
transition: none !important;
}
.army_info_skills [id^="skill_name"]:hover {
color: #c9b087;
}
#easyTooltip {
width: auto;
min-width: auto;
max-width: 320px;
font-size: 0.95em;
padding: 0.9em;
color: #ddd;
border-color: #bbb;
background-color: #1c1c1c;
background-image: none;
text-align: justify;
opacity: 1 !important;
} /* leader_army */
#army_info_div .bookmark {
background-color: #736e6c;
border-color: inherit;
}
#army_info_div .bookmark:hover {
background-color: #a7a7a7;
}
#army_info_div .selected_bookmark {
background-color: #3a3a3a;
}
#bookmark-1 > span,
#army_info_div .info_header_leadershipAmount {
color: inherit;
}
#army_info_div .amount {
color: #d6b47d;
}
#upper_block .content_separator {
background: #555;
} /* skillwheel */
#skills_table .area_wheelInfoPanels {
background-image: none;
background: url("https://dcdn3.heroeswm.ru/i/combat/corner4_lt.png") no-repeat top left, url("https://dcdn3.heroeswm.ru/i/combat/corner4_rt.png") no-repeat top right,
url("https://dcdn3.heroeswm.ru/i/combat/corner4_lb.png") no-repeat bottom left, url("https://dcdn3.heroeswm.ru/i/combat/corner4_rb.png") no-repeat bottom right,
url("https://dcdn3.heroeswm.ru/i/combat/winChatDesktop_border_t.png") top left repeat-x, url("https://dcdn3.heroeswm.ru/i/combat/winChatDesktop_border_b.png") bottom left repeat-x,
url("https://dcdn3.heroeswm.ru/i/combat/winChatDesktop_border_l.png") top left repeat-y, url("https://dcdn3.heroeswm.ru/i/combat/winChatDesktop_border_r.png") top right repeat-y;
background-size: 20px, 20px, 20px, 20px, auto, auto, auto, auto, auto;
background-color: #353535;
outline: 1px solid gray;
}
#skills_table .info_head3Wheel {
color: #cca568;
}
#skills_table .wheel_abilitiesList {
color: #e0c497;
}
#skills_table .info_head3_2Wheel {
color: #888;
}
#skill_cur_cost {
color: inherit;
}
#win_Loader {
-webkit-filter: invert(0.9) sepia(0.7);
filter: invert(0.9) sepia(0.7);
} /* arts_for_monsters */
[data-page="arts_for_monsters"] i {
color: #caa472;
} /* sms */
img[src$="sms_flag.gif"] {
-webkit-filter: invert(0.9) sepia(1) grayscale(1);
filter: invert(0.9) sepia(1) grayscale(1);
}
[data-page="sms"] td.wbwhite b {
color: inherit !important;
}
[data-page^="sms_"] td.wbcapt {
color: #ccc;
background-color: #444;
}
[data-page^="sms"] a[href] > font[color="#5ACE5A"] > b {
color: #5ace5a !important;
}
[data-page="sms"] a[href="sms.php?filter=new"],
[data-page="sms_clans"] td[align] > a[href^="/sms_"] {
text-decoration: none;
}
[data-page="sms"] [name="data"] {
color: #ccc;
background-color: #1d1d1d;
} /* sms_clans */
[data-page="sms_clans"] td.wbcapt > b {
color: inherit !important;
} /* tour_hist */
[data-page$="_hist"] [style^="BACKGROUND"] {
background-color: #333 !important;
}
[data-page$="_hist"] [style^="BACKGROUND-COLOR: #d3d1c6"],
[data-page$="_hist"] [style^="BACKGROUND-COLOR: #F5F3EA"] {
background-color: #444 !important;
}
img[src$="/mtp1.jpg"],
img[src$="/mtp2.jpg"],
img[src$="/mtp3.jpg"] {
-webkit-filter: invert(0.9) sepia(0.5);
filter: invert(0.9) sepia(0.5);
} /* donate */
[data-page^="hwm_donate"] div[style*="color: #000000"] {
color: inherit !important;
}
[data-page^="hwm_donate"] .pay-sys {
background-color: #353535;
} /* home */
[data-page="home"] table[width="90%"] b {
color: #d0bda6;
}
[data-page="home"] table[width="90%"] font[color="black"] {
color: #bbb;
} /* script: hwm_time_restore */
#main_top_table [src$="/dragon__left.jpg"] + div {
z-index: 2;
}
#main_top_table .hwm_tb * {
color: tan;
}
#main_top_table .hwm_tb span {
color: #59a7ad !important;
}
#main_top_table .hwm_tb span[style$="rgb(255, 0, 0);"] {
color: #ff9800 !important;
}
#main_top_table .hwm_tb img {
-webkit-filter: none;
filter: none;
}
#main_top_table .hwm_tb td[width="5"] > img {
visibility: visible;
}
#main_top_table .hwm_tb a:hover {
color: #ccc !important;
}
#bgCenter {
background-color: #333 !important;
} /* script: SetsMaster */
#main_top_table div[id^="menuSetsTab"] {
color: tan !important;
border-color: tan;
}
#main_top_table div[id^="menuSetsTab"] * {
color: inherit !important;
}
#main_top_table div[id^="menuSetsTab"] li:hover {
color: #ccc !important;
}
#main_top_table div[id^="menuSetsTab"] b[style$="rgb(0, 255, 0);"] {
color: #76c5cc !important;
}
[data-page="army"] center:nth-of-type(2) table {
background-color: #555;
border: 1px solid;
border-collapse: initial !important;
} /* ========================= */ /* inventory */
[data-page="inventory"] .art_durability_hidden {
display: block !important;
opacity: 1 !important;
}
[data-page="inventory"] .hwm_hint_css {
color: #222;
background: #eee;
border: 2px solid #888 !important;
z-index: 100;
}
:root .container_block {
color: #eee;
background-color: #333;
box-shadow: inset 0 0 0 1px #c2b4a3;
}
:root .filter_tab {
background-color: #fff;
-webkit-filter: invert(0.9) grayscale(0.6);
filter: invert(0.9) grayscale(0.6);
}
:root .filter_tab_active {
background-color: #ddd;
}
:root .inv_scroll_content {
color: #eee;
background-color: #222;
border: 1px solid;
}
:root .inv_scroll_content_expand_sign {
-webkit-filter: invert(0.9);
filter: invert(0.9);
}
:root .inv_note_kukla {
background-color: transparent;
box-shadow: none;
}
:root #inv_expandedBlock {
margin-top: 0.4em;
}
:root .btn_standard:not(.btn_disabled) {
color: #222;
background-color: #ddd;
text-shadow: none;
}
:root .btn_on_edit {
background-color: #fff !important;
}
:root #inv_menu {
padding: 0.4em;
background-color: rgba(225, 225, 225, 0.9);
z-index: 10;
}
:root #inv_menu,
:root .inv_item_info font {
color: #222;
}
:root .inv_item_select_img[cat] {
-webkit-filter: invert(0.8) grayscale(0.6);
filter: invert(0.8) grayscale(0.6);
}
:root #inv_menu a,
:root #inv_menu a > * {
color: #ae5650;
}
:root .inventory_item_div_wide {
background-color: #444;
}
.inventory_item_in_rent ~ div .cre_mon_image2 {
background-color: rgba(113, 196, 223, 0.3);
}
.inventory_item_broken ~ div .cre_mon_image2 {
background-color: rgb(255, 17, 0, 0.3);
}
.s_art {
background-color: #88887e;
}
.global_container_block {
background-color: #666663;
}
.map_obj_table_div_gray {
background-color: #201c1c !important;
}
.global_container_block_header {
background-color: #201f1e;
}
.map_obj_head {
background-color: #5b5954 !important;
}
.global_table_div table tbody tr:nth-of-type(2n+1) {
background-color: #201c1c;
}
.global_table_div table tbody tr:nth-of-type(2n) {
background-color: #201c1c;
}
.hwm_recruit_ramka {
background-color: #6f6e6a !important;
}
</style>`);
const coloredHeaderStyle = parseNode(`<style>
#main_top_table b,
#main_top_table table.hwm_tb * {
color: #ffd875;
}
#main_top_table div[id^="menuSetsTab"] {
color: #ffd875 !important;
}
#main_top_table td[width="88"] {
border-width: 0 !important;
}
#main_top_table td[height="17"] {
color: #ccc;
}
#main_top_table img,
#main_top_table td {
-webkit-filter: none !important;
filter: none !important;
}
#main_top_table img[src$="_topll_80.jpg"],
#main_top_table img[src$="_topr2_80.jpg"] {
content: url("https://i.ibb.co/frf905t/res-line-topll-80.png");
}
#main_top_table img[src$="_top0.jpg"],
#main_top_table img[src$="_toprr.jpg"] {
content: url("https://i.ibb.co/T8pgh0r/res-line-top0.png");
}
#main_top_table img[src$="logot.jpg"] {
content: url("https://i.ibb.co/nsWmc8k/logot.png");
}
#main_top_table td[style$="/right_big.jpg);"] {
background-image: url("https://i.ibb.co/9hK2xrd/right-big.png") !important;
}
#main_top_table td[style*="/lbkg.jpg"] {
background-image: url("https://i.ibb.co/b5q3Dwj/lbkg.png") !important;
}
#main_top_table img[src*="dragon"] {
content: url("https://i.ibb.co/wgLHkFj/dragon-left.png");
}
#main_top_table img[src$="/left_big0_56.jpg"] {
content: url("https://i.ibb.co/y69yYWQ/left-big0-56.png");
}
#main_top_table img[src$="/left_big2_92.jpg"] {
content: url("https://i.ibb.co/xm7g9sD/left-big2-92.png");
}
#main_top_table img[src$="dec_88.jpg"] {
content: url("https://i.ibb.co/gVJb89v/ldec-88.png");
}
#main_top_table img[src$="part.jpg"] {
content: url("https://i.ibb.co/p4zM1ym/lpart.png");
}
#main_top_table img[src$="32_39.jpg"] {
content: url("https://i.ibb.co/sgTGdSb/h-top-32-39.png");
}
#main_top_table img[src$="32_10.jpg"] {
content: url("https://i.ibb.co/GdGQsWm/h-top-32-10.png");
}
#main_top_table img[src*="_bot"][src$="_80.jpg"] {
content: url("https://i.ibb.co/mFwH3rS/res-line-botl-80.jpg");
}
#main_top_table img[src$="t_end.jpg"] {
content: url("https://i.ibb.co/n650yBY/t-end.png");
}
#main_top_table img[src$="_bot0.jpg"],
#main_top_table img[src$="_botrr.jpg"] {
content: url("https://i.ibb.co/Dfdj0gZ/res-line-bot0.png");
}
#main_top_table td[style$="/bkgtop.jpg);"] {
position: relative;
background-image: url("https://i.ibb.co/rc0qfLf/res-line-topc.png") !important;
}
#main_top_table td[style$="/bkgtop.jpg);"]:before {
content: "";
width: 100%;
height: 2px;
position: absolute;
background-color: #222;
}
#main_top_table img[src$="topr2_80.jpg"],
#main_top_table img[src$="botr_80.jpg"],
#main_top_table img[src$="rdec_88.jpg"],
#main_top_table img[src$="rpart.jpg"],
#main_top_table img[src$="line_32_39.jpg"],
#main_top_table img[src$="right_36.jpg"] {
-o-transform: scaleX(-1);
-moz-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
transform: scaleX(-1);
}
</style>`);
main();
function main() {
addStyle(":root {overflow-y: auto;} :root > body {overflow-y: visible;}");
addStyle(`#night_mode_switcher {width: 22px; height: 22px; position: fixed; right: 10px; bottom: 10px; margin: 0; padding: 0; color: transparent; outline: none; border: 1px solid #888; border-radius: 50%; background: url("https://i.ibb.co/dJCMwGN/switcher.png") center /contain;background-color: #333;cursor: pointer;z-index: 9999;opacity: .9;transition: transform .3s;}#night_mode_switcher:hover {opacity: 1;}[data-page="frames"] #night_mode_switcher {display: none;}`);
document.documentElement.setAttribute('data-page', location.pathname.slice(1).replace(/\.(php|html)$/, ''));
const switcher = addElement("button", { id: "night_mode_switcher" }, document.body);
switcher.hidden = getPlayerBool("nightModeSwitcherHidden");
switcher.addEventListener("click", function() { setPlayerValue("nightMode", !getPlayerBool("nightMode")); applyNightMode(); });
applyNightMode();
drawSettings();
}
function applyNightMode() {
const nightMode = getPlayerBool("nightMode");
document.getElementById("night_mode_switcher").title = isEn ? (nightMode ? "Disable night mode" : "Enable night mode") : (nightMode ? "Выключить ночную тему" : "Включить ночную тему");
if(nightMode) {
document.head.appendChild(nightStyle);
if(getPlayerBool("coloredHeader")) {
document.head.appendChild(coloredHeaderStyle);
}
} else {
nightStyle.remove();
if(getPlayerBool("coloredHeader")) {
coloredHeaderStyle.remove();
}
}
}
function drawSettings() {
if(location.pathname == '/pers_settings.php') {
const search = document.querySelector('td.wbwhite[colspan="2"]').parentNode;
search.insertAdjacentHTML("beforebegin", `
<tr>
<td class=wblight colspan=2>
<b>${isEn ? "Night mode settings" : "Ночная тема: настройки"}</b>
</td>
</tr>
<tr hidden="hidden">
<td class=wbwhite style="width: 35%;">
${isEn ? "Colored cap" : "Цветная шапка"}
</td>
<td class=wbwhite align=left>
<input id=coloredHeaderCheckbox type=checkbox />
</td>
</tr>
<tr>
<td class=wbwhite style="width: 35%;">
${isEn ? 'Hide switcher' : 'Скрывать кнопку-переключатель'}
</td>
<td class=wbwhite align=left>
<input id=btnHiddenCheckbox type=checkbox />
</td>
</tr>`);
document.getElementById("coloredHeaderCheckbox").checked = getPlayerBool("coloredHeader");
document.getElementById("coloredHeaderCheckbox").addEventListener("change", function() { setPlayerValue("coloredHeader", this.checked); this.checked ? document.head.appendChild(coloredHeaderStyle) : coloredHeaderStyle.remove(); });
document.getElementById("btnHiddenCheckbox").checked = getPlayerBool("nightModeSwitcherHidden");
document.getElementById("btnHiddenCheckbox").addEventListener("change", function() { setPlayerValue("nightModeSwitcherHidden", this.checked); switcher.hidden = this.checked; });
}
}
function parseNode(html) {
const div = addElement('div', { innerHTML: html });
return div.firstChild.cloneNode(true);
}
// Array and object
function groupBy(list, keyFieldOrSelector) { return list.reduce(function(t, item) { const keyValue = typeof keyFieldOrSelector === 'function' ? keyFieldOrSelector(item) : item[keyFieldOrSelector]; (t[keyValue] = t[keyValue] || []).push(item); return t; }, {}); };
function getKeyByValue(object, value) { return Object.keys(object).find(key => object[key] === value); }
function findKey(obj, selector) { return Object.keys(obj).find(selector); }
function pushNew(array, newValue) { if(array.indexOf(newValue) == -1) { array.push(newValue); } }
function sortBy(field, reverse, evaluator) {
const key = evaluator ? function(x) { return evaluator(x[field]); } : function(x) { return x[field]; };
return function(a, b) { return a = key(a), b = key(b), (reverse ? -1 : 1) * ((a > b) - (b > a)); }
}
// HttpRequests
function getRequest(url, overrideMimeType = "text/html; charset=windows-1251") {
return new Promise((resolve, reject) => {
GM.xmlHttpRequest({ method: "GET", url: url, overrideMimeType: overrideMimeType,
onload: function(response) { resolve((new DOMParser).parseFromString(response.responseText, "text/html")); },
onerror: function(error) { reject(error); }
});
});
}
function getRequestText(url, overrideMimeType = "text/html; charset=windows-1251") {
return new Promise((resolve, reject) => {
GM.xmlHttpRequest({ method: "GET", url: url, overrideMimeType: overrideMimeType,
onload: function(response) { resolve(response.responseText); },
onerror: function(error) { reject(error); }
});
});
}
function postRequest(url, data) {
return new Promise((resolve, reject) => {
GM.xmlHttpRequest({ method: "POST", url: url, headers: { "Content-Type": "application/x-www-form-urlencoded" }, data: data,
onload: function(response) { resolve(response); },
onerror: function(error) { reject(error); }
});
});
}
function fetch({ url, method = 'GET', type = 'document', body = null }) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.responseType = type;
xhr.onload = () => {
if (xhr.status === 200) return resolve(xhr.response);
throwError(`Error with status ${xhr.status}`);
};
xhr.onerror = () => throwError(`HTTP error with status ${xhr.status}`);
xhr.send(body);
function throwError(msg) {
const err = new Error(msg);
err.status = xhr.status;
reject(err);
}
});
}
// Storage
function getValue(key, defaultValue) { return GM_getValue(key, defaultValue); };
function setValue(key, value) { GM_setValue(key, value); };
function deleteValue(key) { return GM_deleteValue(key); };
function getPlayerValue(key, defaultValue) { return getValue(`${key}${PlayerId}`, defaultValue); };
function setPlayerValue(key, value) { setValue(`${key}${PlayerId}`, value); };
function deletePlayerValue(key) { return deleteValue(`${key}${PlayerId}`); };
function getPlayerBool(valueName, defaultValue = false) { return getBool(valueName + PlayerId, defaultValue); }
function getBool(valueName, defaultValue = false) {
const value = getValue(valueName);
//console.log(`valueName: ${valueName}, value: ${value}, ${typeof(value)}`)
if(value != undefined) {
if(typeof(value) == "string") {
return value == "true";
}
if(typeof(value) == "boolean") {
return value;
}
}
return defaultValue;
}
function setOrDeleteNumberValue(key, value) {
if(!value || value == "" || isNaN(Number(value))) {
deleteValue(key);
} else {
setValue(key, value);
}
}
function setOrDeleteNumberPlayerValue(key, value) { setOrDeleteNumberValue(key + PlayerId, value); }
function getStorageKeys(filter) { return listValues().filter(filter); }
// Html DOM
function addElement(type, data = {}, parent = undefined, insertPosition = "beforeend") {
const el = document.createElement(type);
for(const key in data) {
if(key == "innerText" || key == "innerHTML") {
el[key] = data[key];
} else {
el.setAttribute(key, data[key]);
}
}
if(parent) {
if(parent.insertAdjacentElement) {
parent.insertAdjacentElement(insertPosition, el);
} else if(parent.parentNode) {
switch(insertPosition) {
case "beforebegin":
parent.parentNode.insertBefore(el, parent);
break;
case "afterend":
parent.parentNode.insertBefore(el, parent.nextSibling);
break;
}
}
}
return el;
}
function addStyle(css) { addElement("style", { type: "text/css", innerHTML: css }, document.head); }
function getParent(element, parentType, number = 1) {
if(!element) {
return;
}
let result = element;
let foundNumber = 0;
while(result = result.parentNode) {
if(result.nodeName.toLowerCase() == parentType.toLowerCase()) {
foundNumber++;
if(foundNumber == number) {
return result;
}
}
}
}
function getNearestAncestorSibling(node) {
let parentNode = node;
while((parentNode = parentNode.parentNode)) {
if(parentNode.nextSibling) {
return parentNode.nextSibling;
}
}
}
function getNearestAncestorElementSibling(node) {
let parentNode = node;
while((parentNode = parentNode.parentNode)) {
if(parentNode.nextElementSibling) {
return parentNode.nextElementSibling;
}
}
}
function nextSequential(node) { return node.firstChild || node.nextSibling || getNearestAncestorSibling(node); }
function nextSequentialElement(element) { return element.firstElementChild || element.nextElementSibling || getNearestAncestorElementSibling(element); }
function getSequentialsUntil(firstElement, lastElementTagName) {
let currentElement = firstElement;
const resultElements = [currentElement];
while((currentElement = nextSequential(currentElement)) && currentElement.nodeName.toLowerCase() != lastElementTagName.toLowerCase()) {
resultElements.push(currentElement);
}
if(currentElement) {
resultElements.push(currentElement);
}
return resultElements;
}
function findChildrenTextContainsValue(selector, value) { return Array.from(document.querySelectorAll(selector)).reduce((t, x) => { const match = Array.from(x.childNodes).filter(y => y.nodeName == "#text" && y.textContent.includes(value)); return [...t, ...match]; }, []); }
// Popup panel
function createPupupPanel(panelName, panelTitle, fieldsMap, panelToggleHandler) {
const backgroundPopupPanel = addElement("div", { id: panelName, style: "position: fixed; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.4); z-index: 200;" }, document.body);
backgroundPopupPanel.addEventListener("click", function(e) { if(e.target == this) { hidePupupPanel(panelName, panelToggleHandler); }});
const topStyle = isMobileDevice ? "" : "top: 50%; transform: translateY(-50%);";
const contentDiv = addElement("div", { style: `${topStyle} padding: 5px; display: flex; flex-wrap: wrap; position: relative; margin: auto; padding: 0; width: fit-content; background-image: linear-gradient(to right, #eea2a2 0%, #bbc1bf 19%, #57c6e1 42%, #b49fda 79%, #7ac5d8 100%); border: 1mm ridge rgb(211, 220, 50);` }, backgroundPopupPanel);
if(panelTitle) {
addElement("b", { innerHTML: panelTitle, style: "text-align: center; margin: auto; width: 90%; display: block;" }, contentDiv);
}
const divClose = addElement("span", { id: panelName + "close", title: isEn ? "Close" : "Закрыть", innerHTML: "×", style: "cursor: pointer; font-size: 20px; font-weight: bold;" }, contentDiv);
divClose.addEventListener("click", function() { hidePupupPanel(panelName, panelToggleHandler); });
addElement("div", { style: "flex-basis: 100%; height: 0;"}, contentDiv);
if(fieldsMap) {
let contentTable = addElement("table", { style: "flex-basis: 100%; width: min-content;"}, contentDiv);
for(const rowData of fieldsMap) {
if(rowData.length == 0) { // Спомощью передачи пустой стороки-массива, указываем, что надо начать новую таблицу после брейка
addElement("div", { style: "flex-basis: 100%; height: 0;"}, contentDiv);
contentTable = addElement("table", undefined, contentDiv);
continue;
}
const row = addElement("tr", undefined, contentTable);
for(const cellData of rowData) {
const cell = addElement("td", undefined, row);
if(cellData) {
if(typeof(cellData) == "string") {
cell.innerText = cellData;
} else {
cell.appendChild(cellData);
}
}
}
}
}
if(panelToggleHandler) {
panelToggleHandler(true);
}
return contentDiv;
}
function showPupupPanel(panelName, panelToggleHandler) {
const backgroundPopupPanel = document.getElementById(panelName);
if(backgroundPopupPanel) {
backgroundPopupPanel.style.display = '';
if(panelToggleHandler) {
panelToggleHandler(true);
}
return true;
}
return false;
}
function hidePupupPanel(panelName, panelToggleHandler) {
const backgroundPopupPanel = document.getElementById(panelName);
backgroundPopupPanel.style.display = 'none';
if(panelToggleHandler) {
panelToggleHandler(false);
}
}
// Script autor and url
function getScriptLastAuthor() {
let authors = GM_info.script.author;
if(!authors) {
const authorsMatch = GM_info.scriptMetaStr.match(/@author(.+)\n/);
authors = authorsMatch ? authorsMatch[1] : "";
}
const authorsArr = authors.split(",").map(x => x.trim()).filter(x => x);
return authorsArr[authorsArr.length - 1];
}
function getDownloadUrl() {
let result = GM_info.script.downloadURL;
if(!result) {
const downloadURLMatch = GM_info.scriptMetaStr.match(/@downloadURL(.+)\n/);
result = downloadURLMatch ? downloadURLMatch[1] : "";
result = result.trim();
}
return result;
}
function getScriptReferenceHtml() { return `<a href="${getDownloadUrl()}" title="${isEn ? "Check for update" : "Проверить обновление скрипта"}" target=_blanc>${GM_info.script.name} ${GM_info.script.version}</a>`; }
function getSendErrorMailReferenceHtml() { return `<a href="sms-create.php?mailto=${getScriptLastAuthor()}&subject=${isEn ? "Error in" : "Ошибка в"} ${GM_info.script.name} ${GM_info.script.version} (${GM_info.scriptHandler} ${GM_info.version})" target=_blanc>${isEn ? "Bug report" : "Сообщить об ошибке"}</a>`; }
// Server time
function getServerTime() { return Date.now() - parseInt(getValue("ClientServerTimeDifference", 0)); }
function getGameDate() { return new Date(getServerTime() + 10800000); } // Игра в интерфейсе всегда показывает московское время // Это та дата, которая в toUTCString покажет время по москве
function toServerTime(clientTime) { return clientTime - parseInt(GM_getValue("ClientServerTimeDifference", 0)); }
function toClientTime(serverTime) { return serverTime + parseInt(GM_getValue("ClientServerTimeDifference", 0)); }
function truncToFiveMinutes(time) { return Math.floor(time / 300000) * 300000; }
function today() { const now = new Date(getServerTime()); now.setHours(0, 0, 0, 0); return now; }
function tomorrow() { const today1 = today(); today1.setDate(today1.getDate() + 1); return today1; }
async function requestServerTime() {
if(parseInt(getValue("LastClientServerTimeDifferenceRequestDate", 0)) + 6 * 60 * 60 * 1000 < Date.now()) {
setValue("LastClientServerTimeDifferenceRequestDate", Date.now());
const responseText = await getRequestText("/time.php");
const responseParcing = /now (\d+)/.exec(responseText); //responseText: now 1681711364 17-04-23 09:02
if(responseParcing) {
setValue("ClientServerTimeDifference", Date.now() - parseInt(responseParcing[1]) * 1000);
}
} else {
setTimeout(requestServerTime, 60 * 60 * 1000);
}
}
// dateString - игровое время, взятое со страниц игры. Оно всегда московское // Как результат возвращаем серверную дату
function parseDate(dateString, isFuture = false, isPast = false) {
//console.log(dateString)
if(!dateString) {
return;
}
const dateStrings = dateString.split(" ");
let hours = 0;
let minutes = 0;
let seconds = 0;
const gameDate = getGameDate();
let year = gameDate.getUTCFullYear();
let month = gameDate.getUTCMonth();
let day = gameDate.getUTCDate();
const timePart = dateStrings.find(x => x.includes(":"));
if(timePart) {
var time = timePart.split(":");
hours = parseInt(time[0]);
minutes = parseInt(time[1]);
if(time.length > 2) {
seconds = parseInt(time[2]);
}
if(dateStrings.length == 1) {
let result = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
if(isPast && result > gameDate) {
result.setUTCDate(result.getUTCDate() - 1);
}
if(isFuture && result < gameDate) {
result.setUTCDate(result.getUTCDate() + 1);
}
//console.log(`result: ${result}, gameDate: ${gameDate}`)
result.setUTCHours(result.getUTCHours() - 3);
return result;
}
}
const datePart = dateStrings.find(x => x.includes("-"));
if(datePart) {
const date = datePart.split("-");
month = parseInt(date[isEn ? (date.length == 3 ? 1 : 0) : 1]) - 1;
day = parseInt(date[isEn ? (date.length == 3 ? 2 : 1) : 0]);
if(date.length == 3) {
const yearText = isEn ? date[0] : date[2];
year = parseInt(yearText);
if(yearText.length < 4) {
year += Math.floor(gameDate.getUTCFullYear() / 1000) * 1000;
}
} else {
if(isFuture && month == 0 && gameDate.getUTCMonth() == 11) {
year += 1;
}
}
}
if(dateStrings.length > 2) {
const letterDateExec = /(\d{2}):(\d{2}) (\d{2}) (.{3,4})/.exec(dateString);
if(letterDateExec) {
//console.log(letterDateExec)
day = parseInt(letterDateExec[3]);
//const monthNames = ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'];
const monthShortNames = ['янв', 'фев', 'март', 'апр', 'май', 'июнь', 'июль', 'авг', 'сент', 'окт', 'ноя', 'дек'];
month = monthShortNames.findIndex(x => x.toLowerCase() == letterDateExec[4].toLowerCase());
if(isPast && Date.UTC(year, month, day, hours, minutes, seconds) > gameDate.getTime()) {
year -= 1;
}
}
}
//console.log(`year: ${year}, month: ${month}, day: ${day}, time[0]: ${time[0]}, time[1]: ${time[1]}, ${new Date(year, month, day, parseInt(time[0]), parseInt(time[1]))}`);
let result = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
result.setUTCHours(result.getUTCHours() - 3);
return result;
}
// Misc
async function initUserName() {
if(location.pathname == "/pl_info.php" && getUrlParamValue(location.href, "id") == PlayerId) {
//console.log(document.querySelector("h1").innerText)
setPlayerValue("UserName", document.querySelector("h1").innerText);
}
if(location.pathname == "/home.php") {
//console.log(document.querySelector(`a[href='pl_info.php?id=${PlayerId}'] > b`).innerText)
setPlayerValue("UserName", document.querySelector(`a[href='pl_info.php?id=${PlayerId}'] > b`).innerText);
}
if(!getPlayerValue("UserName")) {
const doc = await getRequest(`/pl_info.php?id=${PlayerId}`);
setPlayerValue("UserName", doc.querySelector("h1").innerText);
}
}
function getUrlParamValue(url, paramName) { return (new URLSearchParams(url.split("?")[1])).get(paramName); }
function showBigData(data) { console.log(data); /*addElement("TEXTAREA", { innerText: data }, document.body);*/ }
function round0(value) { return Math.round(value * 10) / 10; }
function round00(value) { return Math.round(value * 100) / 100; }
function mobileCheck() {
let check = false;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
return check;
};
// MutationObserver
function observe(targets, handler, config = { childList: true, subtree: true }) {
targets = Array.isArray(targets) ? targets : [targets];
targets = targets.map(x => { if(typeof x === 'function') { return x(document); } return x; }); // Можем передавать не элементы, а их селекторы
const ob = new MutationObserver(async function(mut, observer) {
//console.log(`Mutation start`);
observer.disconnect();
if(handler.constructor.name === 'AsyncFunction') {
await handler();
} else {
handler();
}
for(const target of targets) {
if(target) {
observer.observe(target, config);
}
}
});
for(const target of targets) {
if(target) {
ob.observe(target, config);
}
}
}
// UpdatePanels
// Если используется url, то это должна быть та же локация с другими параметрами
async function refreshUpdatePanels(panelSelectors, postProcessor, url = location.href) {
panelSelectors = Array.isArray(panelSelectors) ? panelSelectors : [panelSelectors];
let freshDocument;
for(const panelSelector of panelSelectors) {
const updatePanel = panelSelector(document);
//console.log(panelSelector.toString())
//console.log(updatePanel)
if(updatePanel) {
freshDocument = freshDocument || await getRequest(url);
const freshUpdatePanel = panelSelector(freshDocument);
if(!freshUpdatePanel) {
console.log(updatePanel)
continue;
}
if(postProcessor) {
postProcessor(freshUpdatePanel);
}
updatePanel.innerHTML = freshUpdatePanel.innerHTML;
Array.from(updatePanel.querySelectorAll("script")).forEach(x => {
x.insertAdjacentElement("afterend", addElement("script", { innerHTML: x.innerHTML })); // Передобавляем скрипты, как элементы, что они сработали
x.remove();
});
}
}
if(typeof win.hwm_hints_init === 'function') win.hwm_hints_init();
return freshDocument;
}