Twitterのwebでin reply toのテキストを表示させるGreasemonkeyその2
Twitterのwebでin reply toのテキストを表示させるGreasemonkey - えびし日記
のグリモンを改良しました。
↑これに対応するためです…!!!
// ==UserScript== // @name show "in reply to" in twitter // @namespace eibiisii // @description Twitterのin reply toの発言を表示します。 // @include http://twitter.com/* // @include https://twitter.com/* // @exclude http://twitter.com/invitations/* // @exclude http://twitter.com/settings/* // @exclude http://twitter.com/goodies/* // @exclude https://twitter.com/invitations/* // @exclude https://twitter.com/settings/* // @exclude https://twitter.com/goodies/* // @require http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js // ==/UserScript== (function(){ $('.meta a:last-child').each(function(){ //↑変更点 if($(this).hasClass('geocoded_google_link')){//変更点 }else if($(this).is('[rel]')){//変更点 }else{ var hreftext = $(this).attr('href'); var replytext = 'hoge'; $.get(hreftext, function(data){ replytext=data.match('<span class="entry-content">.+?</span>')[0]; replytext = replytext.replace('span','div'); replytext = replytext.replace('class="entry-content"','class="my_class"'); console.log('replytext='+replytext); }); $(this).after('<span class="my_point">★in reply toを見る</span>'); $('.my_point').hover( function(){ $(this).css('cursor','pointer'); }, function(){ $(this).css(''); } ); $(this).next().toggle( function(){ $(this).after(replytext); console.log(replytext); $('.my_class').css({backgroundColor:"#f7f7f7", fontWeight:"bolder", color:"#999999", fontSize:"12px"}); }, function(){ $(this).next().slideUp(); } ); } }); })();
jQueryのif文
「もしisfollowクラスの要素がtrueを含んでいたら、その次の要素のテキストを書き変える」
ということをしたかったのですが、jQueryが思うようにいかなかったので覚え書き。
- html
<span class="isfollow">true</span> <span><input class="follow_check" type="checkbox" name="follow" value="${cld.name}" />フォローする</span>
- jQueryその1
if($(".isfollow").is(":contains('true')")){ $(this).next().text("フォローしています"); }else{ }
↑こう書いたらうまくいかず…。
- jQueryその2
$(".isfollow:contains('true')+span").text("フォローしています");
↑こう書いたらうまくいきました。
とりあえずうまくいったからよかったのですが、
1つ目の書き方がどうしてだめなのかわからなくてもやもやします…。
やったことメモ
13日 リスト管理の手直し(4H)、見た目改善(3H)
Twitterのwebでin reply toのテキストを表示させるGreasemonkey
jQueryが面白かったのでグリモンを書いてみました。
「★in reply toを見る」をクリックすると、
↑こんな感じでin reply toの中身を表示させます。
問題点はいくつかあるのですが…!!(最後に記述)
改善していきたいです。
以下より順を追って覚え書き。
Greasemonkeyを書く準備
- Firefoxをインストール
- アドオン「Greasemonkey」をインストール
- テキストエディタの用意
- javascriptを書きます
ファイル名
hoge.user.js
hogeの部分はなんでもOKで、そのあとに「.user.js」をつけます。
グリモン特有のメタデータ
ソースコードの冒頭に
// ==UserScript== //メタデータ // ==/UserScript== //スクリプト
を記述します。
メタデータの内容は以下のとおりです。
※すべて省略可能。
@name スクリプトの名前 @namespace 自分の名前など @description スクリプトの説明 @include スクリプトの動作対象URL @exclude スクリプトの動作除外URL @require 外部スクリプトのURLを指定(user.jsの先頭に展開される)
ソースコード
jQuery 日本語リファレンス
↑こちらを参考に手探りでガリガリ。
※9/10 17:20コメントをいただき、ソースコードを修正しました。
ありがとうございました!
- twitterirt.user.js
// ==UserScript== // @name my twitter // @namespace eibiisii // @include http://twitter.com/* // @include https://twitter.com/* // @exclude http://twitter.com/invitations/* // @exclude http://twitter.com/settings/* // @exclude http://twitter.com/goodies/* // @exclude https://twitter.com/invitations/* // @exclude https://twitter.com/settings/* // @exclude https://twitter.com/goodies/* // @require http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js // ==/UserScript== (function(){ $('.meta>span+a').each(function(){ var hreftext = $(this).attr('href'); var replytext = 'hoge'; $.get(hreftext, function(data){ // console.log(data.match('<span class="entry-content">.+?</span>')[0]); replytext=data.match('<span class="entry-content">.+?</span>')[0]; replytext = replytext.replace('span','div'); replytext = replytext.replace('class="entry-content"','class="my_class"'); console.log('replytext='+replytext); }); $(this).after('<span class="my_point">★in reply toを見る</span>'); $('.my_point').hover( function(){ $(this).css('cursor','pointer'); }, function(){ $(this).css(''); } ); $(this).next().toggle( function(){ $(this).after(replytext); console.log(replytext); $('.my_class').css({backgroundColor:"#f7f7f7", fontWeight:"bolder", color:"#999999", fontSize:"12px"}); }, function(){ $(this).next().slideUp(); } ); }); })();
致命的な問題点!
-日本語設定でなければ使えない…
--「hoge宛」からスクリーンネームをとってきているからなのですが、ほかに方法が思いつかず…げふん
-
- ※コメントをいただき解決しました!ありがとうございました。
- 最初に読み込んだ20件にしか反映されない
- 「もっと読む」以降には反映されません…
改良
- 2010/9/14
- Twitterのwebでin reply toのテキストを表示させるGreasemonkeyその2 - えびし日記
- 位置情報の機能(「ここから」)に反応してしまうのを修正