Advertisement
etete

Untitled

Dec 14th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Поле имя на 2ch.hk
  3. // @namespace   sosach
  4. // @include     http*://2ch.hk/*
  5. // @require     http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
  6. // @version     1
  7. // @grant           GM_getValue
  8. // @grant           GM_setValue
  9. // @grant           GM_deleteValue
  10. // @grant           GM_openInTab
  11. // @grant           GM_xmlhttpRequest
  12. // @grant           GM.getValue
  13. // @grant           GM.setValue
  14. // @grant           GM.deleteValue
  15. // @grant           GM.xmlHttpRequest
  16. // @grant           unsafeWindow
  17. // ==/UserScript==
  18.  
  19. $(function(){
  20.   var appendInfo = [
  21.     {$form : $("#postform"), appendFunc: appendNameBlockToPostform},
  22.     {$form : $("#qr-postform"), appendFunc: appendNameBlockToQrPostform}
  23.   ];
  24.  
  25.   appendInfo.forEach(function(info){
  26.     if(info.$form.length === 0){
  27.       return;
  28.     }    
  29.     var $name = info.$form.find("[name=name]");
  30.     var isNameInputExists = ($name.length > 0);
  31.     if(!isNameInputExists){
  32.       if($.isFunction(info.appendFunc)){
  33.         info.appendFunc(info.$form);
  34.         $name = info.$form.find("[name=name]");
  35.       }            
  36.     }
  37.     configureNameInput($name);
  38.   });  
  39.  
  40.   //******************************************************
  41.  
  42.   function appendNameBlockToPostform($form){
  43.     var nameHtml = "<tr class='name'><td class='label desktop'><label for='name'>Имя</label></td><td><input value='' id='name' name='name' size='30' placeholder='Имя' type='text'></td></tr>";    
  44.     $form.find("tr.mail").after(nameHtml);    
  45.   }
  46.  
  47.   function appendNameBlockToQrPostform($form){
  48.     var nameHtml = "<div class='qr-mail'><input name='name' id='qr-name' placeholder='Имя' class='qmail' type='text'></div>";    
  49.     $form.find("div.qr-mail").before(nameHtml);  
  50.   }
  51.  
  52.   //******************************************************
  53.  
  54.   function configureNameInput($name){
  55.       var key = "2ch_name";
  56.       $name.on("input", function(){
  57.         var value = $name.val();
  58.         localStorage.setItem(key, value);
  59.       });
  60.  
  61.       var restoredValue = localStorage.getItem(key);  
  62.       if(restoredValue){
  63.         $name.val(restoredValue);      
  64.       }
  65.   }
  66.  
  67. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement