當gamefaqs上瀏覽,我的Greasemonkey腳本一個與Firefox版本56打破了這是一個非常簡單的一個:我的頭在哪裏?
// ==UserScript==
// @name MakeSignaturesBlack
// @namespace tarelessar
// @description Makes the signatures black again
// @include https://*.gamefaqs.com/*
// @version 1
// @grant none
// @run-at document-start
// ==/UserScript==
//Makes signatures black I guess
var sheet = document.createElement ('style')
sheet.innerHTML = ".signature {color: inherit !important}";
document.head.appendChild(sheet);
這個劇本的作者是改變網站以黑灰色簽名條,並已工作了直到Firefox的第54版。之後,它在版本56上停止工作。
當我煩惱它時,發現document.head
爲空。從做一個小小的研究,我發現,document.getElementsByTagName("head")[0];
應使用和嘗試:
// ==UserScript==
// @name MakeSignaturesBlack
// @namespace tarelessar
// @description Makes the signatures black again
// @include https://*.gamefaqs.com/*
// @version 1
// @grant none
// @run-at document-start
// ==/UserScript==
//Makes signatures black I guess
var sheet = document.createElement ('style')
sheet.innerHTML = ".signature {color: inherit !important}";
document.head || document.getElementsByTagName("head")[0];.appendChild(sheet);
...它並沒有改變的標誌色。
我在做什麼錯?我怎樣才能改變「頭」元素,使其改變簽名的顏色?
您需要等待DOM加載,然後才能訪問它。 'document.head'很好。使用'addEventListener(「DOMContentLoaded」,function(){'...'});'或者'@ run-at document-start'。 – Xufox
你寫了'a || b; .c()'當你的意思是'(a || b).c()'。 –
document.head不好。當我打開錯誤控制檯時,據說document.head是空的。因此,我需要別的東西來「頭」。另外,裸露在我身邊。我對編碼幾乎一無所知。只是一些基本的東西。對於像我這樣的新手來說,最簡單的做法就是對腳本進行更改並重新發布。 –