cookie内にマイリスト登録するGMスクリプトの修正

ニコニコ動画でcookie内にマイリスト登録するGMスクリプトの修正 - Bouldering & Com.でちゃんと修正した版があります

少しだけjQueryらしくなるようにGreasemonkeyスクリプトを改造してみた - Bouldering & Com.からさらに少しだけ修正

  • in-cookieなマイリストを表示するところに恥ずかしいバグがあって表示されない場合があったのの修正
  • 大きい表示ボタンを押したときに、divがあると大きい画面への変更を失敗するみたいだったので、無駄なdivを作らないように変更

少しだけ幸せになれた。

http://www.ne.jp/asahi/shrkw/shrkw/add_in-cookie_my-list.user.js

変更点のソース

*** add_in-cookie_my-list.0.2.user.js   2007-07-05 00:09:21.000000000 +0900
--- add_in-cookie_my-list.0.3.user.js   2007-07-05 00:07:10.000000000 +0900
***************
*** 26,32 ****
              var _cookie = document.cookie;
              var ar = _cookie.split(";");
              for (var i = 0; i < ar.length; i++) {
!                 if (ar[i].indexOf(_key) == 1) {
                      return ar[i].split("=")[1];
                  }
              }
--- 26,32 ----
              var _cookie = document.cookie;
              var ar = _cookie.split(";");
              for (var i = 0; i < ar.length; i++) {
!                 if (ar[i].indexOf(_key) >= 0) {
                      return ar[i].split("=")[1];
                  }
              }
***************
*** 38,87 ****
          if (String(document.location).indexOf("watch") !=  - 1) {
              function _add_cookie() {
                  var _movie_id = String(document.location).split('/').pop();
!                 var _indi_node = $("span#_indi_node");
!                 if (_indi_node.length == 0) {
!                     _indi_node = $(document.createElement("span"));
!                 }
! //                _indi_node.css("margin", "1em");
!                 _indi_node.attr("id", "_indi_node");
                  // return if already registered
                  if (parsed_cookie.indexOf(_movie_id) !=  - 1) {
!                     _indi_node.html("you are already added to in-cookie my-list");
                  }
                  else {
                      var old_val = parsed_cookie == "" ? parsed_cookie : parsed_cookie + ",";
                      document.cookie = _key + "=" + old_val + _movie_id + "; path=/; expires=Tue, 1-Jan-2030 00:00:00 GMT;";
!                     _indi_node.html("add to in-cookie my-list successfully");
                  }
-                 // indicate of end of adding process
-                 _indi_node.insertAfter("button#_shrkw_button");
              }
  
              var btn = document.createElement("button");
              btn.addEventListener("click", _add_cookie, false);
              btn = $(btn);
              btn.attr("id", "_shrkw_button");
!             btn.css("margin", "0em 1em 0em 0em");
              btn.html("add to in-cookie my-list");
  
              // append
              var target_node;
              if (String(document.location).indexOf("/watch/") !=  - 1) {
!                 target_node = $("form[@name^='mylist_form']");
              }
              else if (String(document.location).indexOf("/watch_naisho/") !=  - 1) {
                  target_node = $("table").get(9);
              }
-             var _btn_area = $(document.createElement("div"));
-             _btn_area.attr("id", "_shrkw_area");
-             _btn_area.css("margin", "1em 0em");
-             _btn_area.append(btn);
  
!             _btn_area.insertAfter(target_node);
          };
  
          // show in-cookie my-list if you see mylist page
          if (String(document.location).indexOf("www.nicovideo.jp/mylist/") !=  - 1) {
              if (parsed_cookie.length == 0) {
                  return;
              }
--- 38,82 ----
          if (String(document.location).indexOf("watch") !=  - 1) {
              function _add_cookie() {
                  var _movie_id = String(document.location).split('/').pop();
! 
                  // return if already registered
                  if (parsed_cookie.indexOf(_movie_id) !=  - 1) {
!                     $("button#_shrkw_button").html("you are already added to in-cookie my-list");
                  }
                  else {
                      var old_val = parsed_cookie == "" ? parsed_cookie : parsed_cookie + ",";
                      document.cookie = _key + "=" + old_val + _movie_id + "; path=/; expires=Tue, 1-Jan-2030 00:00:00 GMT;";
!                     $("button#_shrkw_button").html("add to in-cookie my-list successfully");
                  }
              }
  
              var btn = document.createElement("button");
              btn.addEventListener("click", _add_cookie, false);
              btn = $(btn);
              btn.attr("id", "_shrkw_button");
!             btn.css({
!                 margin:"1em 0em",
!                 position: "absolute",
!                 left:"2em",
!                 top:"10em",
!             });
              btn.html("add to in-cookie my-list");
  
              // append
              var target_node;
              if (String(document.location).indexOf("/watch/") !=  - 1) {
!                 target_node = $("table").get(0);
              }
              else if (String(document.location).indexOf("/watch_naisho/") !=  - 1) {
                  target_node = $("table").get(9);
              }
  
!             btn.insertAfter(target_node);
          };
  
          // show in-cookie my-list if you see mylist page
          if (String(document.location).indexOf("www.nicovideo.jp/mylist/") !=  - 1) {
+ console.log(parsed_cookie.length)
              if (parsed_cookie.length == 0) {
                  return;
              }
***************
*** 133,138 ****
--- 128,134 ----
              _list_area.append(_list_elem);
  
              var movie_ids = parsed_cookie.split(",");
+             movie_ids.reverse();
              for (var i = 0; i < movie_ids.length; i++) {
                  var _list_node = $(document.createElement("li"));
                  var _d = $(document.createElement("div"));