LoginSignup
1
0

More than 5 years have passed since last update.

Google Play Musicで再生してる曲を #nowplaying でツイートするブックマークレット

Last updated at Posted at 2017-01-22

とりあえずということで、シンプルに 『{曲名}』{アーティスト名} と #nowplaying のハッシュタグでツイートするだけ。

javascript:void((function(){
    var i, t, a, tw;
    var s = function(i){
        var e = document.getElementById(i).innerHTML;
        return e
        .replace(/&/g, "%26")
        .replace(/</g, "%3c")
        .replace(/>/g, "%3e");
    };
    t = s("currently-playing-title");
    a = s("player-artist");
    tw = encodeURIComponent("『" + t + "』" + a + "\n#nowplaying");
    void(window.open("https://twitter.com/intent/tweet?text=" + tw));
})());

単純に曲名やアーティスト名を document.getElementById('foo').innerHTML; で取得するだけだと、タイトルに「&」が含まれてたときにツイート文字列が & になるなどブザマな状態になるので、予め置換処理を行ってます(バッドノウハウかも……)。

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