2016-09-17 11 views
1

ウェブサイトの背景を変更したいと思います。問題は、Greasemonkeyの経験がほとんどないことです。私はこのスクリプトを持っている:Greasemonkeyで背景画像を変更しますか?

// ==UserScript== 
// @name  Tamo 
// @namespace TamoImageChanger 
// @include  https://sistema.tamo.lt* 
// @version  1 
// @grant  none 
// ==/UserScript== 
var images = document.getElementsByTagName("img"); 
var x = 0; 
while (x < images.length) { 
    if (images[x].src == "https://sistema.tamo.lt/Content/img/new/login_background2.jpg") { 
     images[x].src = "the image i want to be displayed"; 
    } 
    x = x + 1; 
} 

を私は、このWebページにいるときにのみ動作します:
      https://sistema.tamo.lt/Content/img/new/login_background2.jpg

私はスクリプトはいえ、このWebページで背景を変更したい:
      https://sistema.tamo.lt/Prisijungimas/Login

答えて

1

あなたが訪問しようとしているウェブサイトは、背景画像であり、画像タグではありません。

そして、このスクリプトは実際にはすべての<img/>タグの送信元を変更します。

var images = document.getElementsByTagName("img"); 

私はあなたのやりたいことを達成するためにスクリプトをカスタマイズしました。これをより教育的にするために、私は何が起こるかを段階的に説明します。

// Here I'm retrieving the tag displaying the picture by specifying exact path. 
var image = document.querySelector("body > .container_2 > .col_left"); 

// Here I just change the background image by yours. 
image.style.backgroundImage = "url('INSERT YOUR IMAGE')"; 

- 以下mentionned Brock Adamsとして

EDIT

、あなたはまた、上記のようなのGreaseMonkeyスタイルを同じ作業を達成することができます。

GM_addStyle("div[style*='login_background2.jpg'] {background-image: url('INSERT YOUR IMAGE')!important;} ") 
+0

または、 '' GM_addStyle() '](https://wiki.greasespot.net/GM_addStyle)、[[スタイリッシュアドオン](https://userstyles.org/) div [style * = 'login_background2.jpg'] {背景画像:URL( 'あなたの画像を挿入する')!重要;} '。 –

+0

これは興味深いコメントです。しばらく私はGMを使用していなかったので、私はその結果について確信しています。 GM_addStyleで回答を編集するつもりですありがとう! –

+0

ありがとうございました!このスクリプトは完璧に動作します! – Mantvydas

関連する問題