LoginSignup
1
0

More than 3 years have passed since last update.

楽天のラッキーくじをちょっと使いやすくしてみた2

Posted at

楽天のラッキーくじをちょっと使いやすくしてみた その2

前回の記事
楽天のラッキーくじをちょっと使いやすくしてみた

前回はトップページのPRやSPを削除してPCだけを表示するという記事を書きました。

今回は開いた先のくじをクリックするプログラムを書きました。
時々失敗するのでまだ検証中

作ってみよう

環境

macOS Catalina ver 10.15.7
GoogleChrome 86

Chromeの拡張機能

拡張機能は省略

プログラムについて

プログラムの内容

function foo(){
    let image = document.getElementById("entry");
    console.log("events");
    if(image.getAttribute("src").indexOf("entry.gif")){
        console.log("entry!")
        image.click();
    }
}
let image = document.getElementById("entry");
image.setAttribute("onload","foo()");

簡単な説明

関数foo()の中身

let image = document.getElementById("entry");
画像を取得して
console.log("events");
consoleに書き込む

if(image.getAttribute("src").indexOf("entry.gif"))
画像のsrcにentry.gifが含まれていたら
console.log("entry!")
consoleに書き込んで
image.click();
画像をクリックする

これだけじゃ画像が読み込み中とかはエラーになっちゃうので、
ページ作成時に
image.setAttribute("onload","foo()");
画像にonload時にfoo関数を呼び出すように書き込む。

これで画像が読み込まれた時に、
画像のsrcにentry.gifが含まれていたら、
画像をクリックしてくれるプログラムの完成

完成はしたんだけど...

時々失敗するので確実にするためには何か考える必要がある
sleepだと他の処理も止まる可能性があるので、
非同期関数とかよくわかってないけどお勉強してもう少し楽にできる方法を模索しましょうねという感じ...

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0