Greasemonkey : 웹 페이지에서 텍스트를 변경 하시겠습니까?
-
22-07-2019 - |
문제
나는 기능을 사용했다 :
document.getElementsByTagName('strong')
해당 유형의 형식이있는 페이지에서 모든 텍스트를 가져옵니다. HTML은 다음과 같습니다.
<td align="center" valign="bottom"><H1><font size="+4"><strong>TEXT_HERE</strong></font> <br>
"Text_here"를 다른 것으로 변경하거나 모두 함께 제거하고 싶습니다. 어떻게 할 수 있습니까?
도와 주셔서 미리 감사드립니다 :)
해결책
for 루프로?
var strongElems = document.getElementsByTagName('strong');
var wantToHide = true || false;
for (var i=0; i<strongElems.length; i++)
{
var thisElem = strongElems[i];
if (wantToHide)
{
thisElem.style.display = "none"; // hide it
}
else
{
thisElem.textContent = "something else"; // change it
}
}
다른 팁
// ==UserScript==
// @name MyScript
// @namespace http://example.com
// @description Example
// @include *
//
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js
// ==/UserScript==
var shouldHide = false;
$('strong').each(function() {
if(shouldHide) {
$(this).hide();
} else {
$(this).text("New Text");
}
});
웹 페이지에서 텍스트를 변경하고 싶을 때 Greasemonkey 솔루션을 기반으로합니다. 멍청한. 교체 쌍을 목록으로 쉽게 정의 할 수있는 것을 좋아했습니다.
replacements = {
"old": "new",
"foo": "bar",
};
즉, Tomalak의 솔루션도 확인하겠습니다. 이 질문을 게시 해 주셔서 감사합니다.
제휴하지 않습니다 StackOverflow