Auto save for OurCoders

none

  1. // ==UserScript==
  2. // @name Auto save for OurCoders
  3. // @namespace http://lovearia.me
  4. // @include http://ourcoders.com/*
  5. // @version 0.0.5
  6. // @grant none
  7. // @description none
  8. // ==/UserScript==
  9.  
  10. $(document).ready(function(){
  11.  
  12. var my_pathname_match_list = [];//{{{
  13. var save_frequency = 3000;
  14.  
  15. my_pathname_match_list.push({
  16. name : 'new thread',
  17. match : /\/thread\/new\/?/,
  18. selector_list : ['#wmd-input', '#title'],
  19. clear_list : ['#newform']
  20. });
  21.  
  22. my_pathname_match_list.push({
  23. name : 'comment for thread',
  24. match : /\/thread\/show\/\d+\/?/,
  25. selector_list : ['#wmd-input'],
  26. clear_list : ['#newreplyform']
  27. });//}}}
  28.  
  29. var AutoSave = function(s_l, c_l, f, p){//{{{
  30. var change_signal = false;
  31.  
  32. var selector_list = s_l;
  33. var clear_list = c_l;
  34. var frequency = f;
  35. var prefix = p;
  36.  
  37. var save = function(){
  38. selector_list.forEach(function(item){
  39. if($(item).val())
  40. localStorage.setItem(p+item, $(item).val());
  41. else
  42. localStorage.removeItem(p+item);
  43.  
  44. console.log(item, ' saved in ', p+item)
  45. change_signal = false;
  46. });
  47. };
  48.  
  49. var clear = function(){
  50. selector_list.forEach(function(item){
  51. localStorage.removeItem(p+item);
  52. console.log(item, ' remove form ', p+item)
  53. change_signal = false;
  54. });
  55. };
  56.  
  57. var init = function(){
  58. selector_list.forEach(function(item){
  59. $(item).change(function(){
  60. change_signal = true;
  61. console.log(item, 'changed');
  62. });
  63.  
  64. var content = localStorage.getItem(p+item);
  65. if(content)
  66. $(item).val(content);
  67. });
  68.  
  69. clear_list.forEach(function(item){
  70. $(item).submit(function(){
  71. clear();
  72. });
  73. });
  74. console.log('init');
  75.  
  76. };
  77.  
  78. this.start = function(){
  79. init();
  80. setInterval(function(){
  81. if(change_signal)
  82. save();
  83. }, f);
  84. };
  85.  
  86. };//}}}
  87.  
  88. var distributor = function(p_m_l){//{{{
  89. var pathname_match_list = p_m_l;
  90.  
  91. pathname_match_list.forEach(function(item){
  92.  
  93. if(location.pathname.match(item.match)){
  94. var as = new AutoSave(item.selector_list, item.clear_list, save_frequency, location.pathname);
  95. as.start();
  96. console.log(item);
  97. }
  98. else{
  99. return;
  100. }
  101.  
  102. });
  103. }//}}}
  104.  
  105. distributor(my_pathname_match_list);
  106.  
  107. });
  108.  
  109.  
  110. //(function(){
  111. //var change = false;
  112. //var title = $('#title');
  113. //var input = $('#wmd-input');
  114. //var form = $('#newform');
  115.  
  116. //(function(){
  117. //if(localStorage.input_cache){
  118. //input.val(localStorage.input_cache);
  119. //title.val(localStorage.title_cache);
  120. //}
  121. //input.after('<p id="is_save" style="background: none repeat scroll 0% 0% rgba(205, 251, 196, 1);"></p>');
  122. //})();
  123.  
  124. //var is_save = $('#is_save');
  125.  
  126. //var save = function(){
  127. //localStorage.input_cache = input.val();
  128. //localStorage.title_cache = title.val();
  129.  
  130. //var d = new Date();
  131. //var d_s = d.toLocaleTimeString();
  132. //is_save.html('latest saved at '+d_s);
  133. //is_save.animate({opacity:'0.6'});
  134. //is_save.animate({opacity:'1'});
  135. //}
  136.  
  137. //input.change(function(){
  138. //change = true;
  139. //});
  140.  
  141. //title.change(function(){
  142. //change = true;
  143. //});
  144.  
  145. //form.submit(function(){});
  146.  
  147. //setInterval(function(){
  148. //if (change){
  149. //save();
  150. //change = false;
  151. //}
  152.  
  153. //}, 10000);
  154.  
  155. //})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址