PDA

Просмотр полной версии : помогите с Tampermonkey


Sep
15.11.2022, 00:57
в стиле profile-body-level-info-progress нет цвета синей полоски а в profile-body-level-info-progress>div есть

но как написать profile-body-level-info-progress>div в

var element = document.getElementsByClassName("profile-body-level-info-progress")[0]; я незнаю

я овер новичок только начел прошу подобного объяснение с примерами если не сложно

код:






var
element
=
document
.
getElementsByClassName
(
"profile-body-level-info-progress"
)
[
0
]
;
element
.
style
.
background
=
"#3bafda"
;




https://i.imgur.com/IIW1zBR.png

https://i.imgur.com/FaPig7X.png

im0rg
15.11.2022, 10:29
JavaScript:






document
.
getElementsByClassName
(
"profile-body-level-info-progress"
)
.
getElementsByTagName
(
'div'
)

Sep
15.11.2022, 14:54
JavaScript:






document
.
getElementsByClassName
(
"profile-body-level-info-progress"
)
.
getElementsByTagName
(
'div'
)





спасибо но не пашет делал так

var element = document.getElementsByClassName("profile-body-level-info-progress").getElementsByTagName('div')

element.style.background="#00ff00";

если меняю в как на фото работает а в скрипте нет

Dogn3my.pngsep · 15 Ноя 2022 в 13:54' data-fancybox="lb-post-1195411" data-lb-caption-extra-html="" data-lb-sidebar-href="" data-single-image="1" data-src="/proxy.php?image=https%3A%2F%2Fi.imgur.com%2FDogn3m y.png&hash=b29232be5facf6a0d11028121889d6d2" style="cursor: pointer;" title="Dogn3my.png">
https://i.imgur.com/Dogn3my.png

полный скрин

https://i.imgur.com/rKK306M.png

если делаю так document.getElementsByClassName("profile-body-level-info-progress")[0].style.background='#00ff00'; то

МЕНЯЕТСЯ НЕ ТО ЧТО Я ХОЧУ

https://i.imgur.com/sDr1yTu.png

И ДА СКРИПТ РАБОТАЕТ ТОЛЬКО КОГДА ПЕРЕЗАГРУЖАЮ СТРАНИЧКУ




ФУЛЛ КОД:






// ==UserScript==
// @name lip-monopoly-one
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author lip
// @match https://monopoly-one.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAE AAAICTAEAOw==
// @grant none
// ==/UserScript==
'use strict'
;
// Your code here...
document
.
getElementsByClassName
(
"_img"
)
[
0
]
.
style
.
backgroundImage
=
"url('https://i.imgur.com/su4kW3N.png')"
;
//
document
.
getElementsByClassName
(
"profile-top-info-main-nick"
)
[
0
]
.
style
.
color
=
'#00ff00'
;
document
.
getElementsByClassName
(
"title title-3"
)
[
0
]
.
style
.
color
=
'ff0000'
;
document
.
getElementsByClassName
(
"profile-body-level-info-rank"
)
[
0
]
.
style
.
color
=
'#ff0000'
;
document
.
getElementsByClassName
(
"profile-top-stat"
)
[
0
]
.
style
.
color
=
'#ffffff'
;
//
//document.getElementsByClassName("profile-body-level-info-progress").getElementsByTagName('div').style.background='#0 0ff00';
//
var
element
=
document
.
getElementsByClassName
(
"profile-body-level-info-progress"
)
.
getElementsByTagName
(
'div'
)
;
element
.
style
.
background
=
"#00ff00"
;

im0rg
15.11.2022, 16:23
спасибо но не пашет делал так
var element = document.getElementsByClassName("profile-body-level-info-progress").getElementsByTagName('div')
element.style.background="#00ff00";

если меняю в как на фото работает а в скрипте нет

https://i.imgur.com/Dogn3my.png

полный скрин

https://i.imgur.com/rKK306M.png

если делаю так document.getElementsByClassName("profile-body-level-info-progress")[0].style.background='#00ff00'; то
МЕНЯЕТСЯ НЕ ТО ЧТО Я ХОЧУ

https://i.imgur.com/sDr1yTu.png

И ДА СКРИПТ РАБОТАЕТ ТОЛЬКО КОГДА ПЕРЕЗАГРУЖАЮ СТРАНИЧКУ



ФУЛЛ КОД:






// ==UserScript==
// @name lip-monopoly-one
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author lip
// @match https://monopoly-one.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAE AAAICTAEAOw==
// @grant none
// ==/UserScript==
'use strict'
;
// Your code here...
document
.
getElementsByClassName
(
"_img"
)
[
0
]
.
style
.
backgroundImage
=
"url('https://i.imgur.com/su4kW3N.png')"
;
//
document
.
getElementsByClassName
(
"profile-top-info-main-nick"
)
[
0
]
.
style
.
color
=
'#00ff00'
;
document
.
getElementsByClassName
(
"title title-3"
)
[
0
]
.
style
.
color
=
'ff0000'
;
document
.
getElementsByClassName
(
"profile-body-level-info-rank"
)
[
0
]
.
style
.
color
=
'#ff0000'
;
document
.
getElementsByClassName
(
"profile-top-stat"
)
[
0
]
.
style
.
color
=
'#ffffff'
;
//
//document.getElementsByClassName("profile-body-level-info-progress").getElementsByTagName('div').style.background='#0 0ff00';
//
var
element
=
document
.
getElementsByClassName
(
"profile-body-level-info-progress"
)
.
getElementsByTagName
(
'div'
)
;
element
.
style
.
background
=
"#00ff00"
;









JavaScript:






// ==UserScript==
// @name lip-monopoly-one
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author lip
// @match https://monopoly-one.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAE AAAICTAEAOw==
// @grant none
// ==/UserScript==
'use strict'
;
// Your code here...
document
.
getElementsByClassName
(
"_img"
)
[
0
]
.
style
.
backgroundImage
=
"url('https://i.imgur.com/su4kW3N.png')"
;
//
document
.
getElementsByClassName
(
"profile-top-info-main-nick"
)
[
0
]
.
style
.
color
=
'#00ff00'
;
document
.
getElementsByClassName
(
"title title-3"
)
[
0
]
.
style
.
color
=
'ff0000'
;
document
.
getElementsByClassName
(
"profile-body-level-info-rank"
)
[
0
]
.
style
.
color
=
'#ff0000'
;
document
.
getElementsByClassName
(
"profile-top-stat"
)
[
0
]
.
style
.
color
=
'#ffffff'
;
//
//document.getElementsByClassName("profile-body-level-info-progress").getElementsByTagName('div').style.background='#0 0ff00';
//
var
element
=
document
.
getElementsByClassName
(
"profile-body-level-info-progress"
)
.
item
(
0
)
.
getElementsByTagName
(
'div'
)
.
item
(
0
)
;
element
.
style
.
background
=
"#00ff00"
;

Sep
15.11.2022, 16:37
JavaScript:






// ==UserScript==
// @name lip-monopoly-one
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author lip
// @match https://monopoly-one.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAE AAAICTAEAOw==
// @grant none
// ==/UserScript==
'use strict'
;
// Your code here...
document
.
getElementsByClassName
(
"_img"
)
[
0
]
.
style
.
backgroundImage
=
"url('https://i.imgur.com/su4kW3N.png')"
;
//
document
.
getElementsByClassName
(
"profile-top-info-main-nick"
)
[
0
]
.
style
.
color
=
'#00ff00'
;
document
.
getElementsByClassName
(
"title title-3"
)
[
0
]
.
style
.
color
=
'ff0000'
;
document
.
getElementsByClassName
(
"profile-body-level-info-rank"
)
[
0
]
.
style
.
color
=
'#ff0000'
;
document
.
getElementsByClassName
(
"profile-top-stat"
)
[
0
]
.
style
.
color
=
'#ffffff'
;
//
//document.getElementsByClassName("profile-body-level-info-progress").getElementsByTagName('div').style.background='#0 0ff00';
//
var
element
=
document
.
getElementsByClassName
(
"profile-body-level-info-progress"
)
.
item
(
0
)
.
getElementsByTagName
(
'div'
)
.
item
(
0
)
;
element
.
style
.
background
=
"#00ff00"
;





спасибо работает но как пофиксить баг что работает только после f5 (обновление страницы)

im0rg
15.11.2022, 16:44
спасибо работает но как пофиксить баг что работает только после f5 (обновление страницы)


DOMContentLoaded

Sep
15.11.2022, 17:14
DOMContentLoaded


а как ее в скрпт вставить ? я хз