English 中文(简体)
开放网站
原标题:Run Javascript when I open any website page
  • 时间:2023-10-10 17:28:58
  •  标签:
  • javascript

I am trying to modify css of a page using a javascript code. My aim is to run this javascript automatically whenever I open a website in Chrome. I have tried several Chrome extensions but it seems that it doesn t do the job (Requestly, Violentmonkey, Tampermonkey).

你们是否在周围工作?

Here is my use case: I use a web app to fulfill orders. In my order page, I have several products and quantity of each product (see screenshot). I want to change the css to make the text bigger and red when the quantity is 2 (and not 1). So I am sure I don t miss anything. I cannot change anything on the web app because it is a third-party app.

这里是我的“javascript”功能,当我手工使用该文字时,它就很好地发挥了作用,但我无法找到一种办法自动做到:

function Change(word) {

  //find all html elements on the page inside the body tag
  let elems = document.querySelectorAll("td");
  // get our replacement ready
  let span = "<span style= color:blue;font-size:22px;font-weight:bold; >" + word + "</span>";
  //loop through all the elements
  for (let x = 0; x < elems.length; x++) {
    // for each element,  split  by the word we re looking for, then  join  it back with the replacement

// put your script function here

    elems[x].innerHTML = elems[x].innerHTML.split(word).join(span);
  }
}

Change( 2 );

感谢你们的帮助!

问题回答

我无法保证,因为没有提供整个法典(包括明文杰森)和目标现场链接,但我怀疑它是一个权威问题。

请查到chrome extension content script docs,并确保正确配置你的表现环境。

我想把这一点作为评论,但我缺乏声誉。 我道歉。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签