KeepScrollPosition

マイページでマイリストから削除したときにスクロール位置を保持するやつ

当前为 2014-05-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name KeepScrollPosition
  3. // @namespace https://github.com/segabito/
  4. // @description マイページでマイリストから削除したときにスクロール位置を保持するやつ
  5. // @include http://www.nicovideo.jp/my/mylist*
  6. // @version 1.0.1
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. // ver 1.0.1 console.log 消し忘れ
  11.  
  12. (function() {
  13. var monkey = (function() {
  14.  
  15. var $ = window.jQuery, $window = $(window);
  16.  
  17. var confirm_org = window.confirm;
  18. var scrollTop = null;
  19. window.confirm = function(msg) {
  20. scrollTop = null;
  21. if (msg !== window.messages.confirm_remove_mylist) {
  22. return confirm_org(msg);
  23. }
  24. var result = confirm_org(msg);
  25. if (result) {
  26. scrollTop = $window.scrollTop();
  27. }
  28. return result;
  29. };
  30. var remove_success = $.proxy(window.messages.remove_success, window.messages);
  31. window.messages.remove_success = function(params) {
  32. if (scrollTop !== null) {
  33. setTimeout(function() {
  34. //console.log('スクロール位置を復元: ', $window.scrollTop() , ' -> ', scrollTop)
  35. $window.scrollTop(scrollTop);
  36. }, 1000);
  37. }
  38. return remove_success(params);
  39. };
  40. })();
  41.  
  42. var script = document.createElement("script");
  43. script.setAttribute("type", "text/javascript");
  44. script.setAttribute("charset", "UTF-8");
  45. script.appendChild(document.createTextNode("(" + monkey + ")()"));
  46. document.body.appendChild(script);
  47.  
  48. })();