Greasy Fork is available in English.

tieba_emotion_helper

贴吧自定义表情批量修改

  1. // ==UserScript==
  2. // @name tieba_emotion_helper
  3. // @namespace firefox
  4. // @include http://tieba.baidu.com/*
  5. // @description 贴吧自定义表情批量修改
  6. // @version 1
  7. // @grant GM_addStyle
  8. // ==/UserScript==
  9. var _window = typeof unsafeWindow == 'undefined' ? window: unsafeWindow;
  10. var $ = _window.$;
  11. var DEFAULT_EMOTION = '[{"title":"hhh",'+
  12. '"url":"http://imgsrc.baidu.com/forum/pic/item/9345d688d43f8794045152ddd31b0ef41ad53a92.jpg",'+
  13. '"thumbnail":"http://imgsrc.baidu.com/forum/abpic/item/9345d688d43f8794045152ddd31b0ef41ad53a92.jpg"},'+
  14. '{"title":"hhh",'+
  15. '"url":"http://imgsrc.baidu.com/forum/pic/item/9345d688d43f8794045152ddd31b0ef41ad53a92.jpg",'+
  16. '"thumbnail":"http://imgsrc.baidu.com/forum/abpic/item/9345d688d43f8794045152ddd31b0ef41ad53a92.jpg"}]';
  17.  
  18. function loadText(){
  19. var emotion = localStorage.customEmotion;
  20. if(emotion==undefined || emotion==null || emotion=="null"){
  21. return DEFAULT_EMOTION;
  22. }
  23. if(emotion.indexOf("|")!=-1)emotion = emotion.substring(emotion.indexOf("|") + 1,emotion.length);
  24. return emotion;
  25. }
  26. function save(){
  27. var data = $("#add_emotion_text").attr("value");
  28. if(data!=""){
  29. try{
  30. JSON.parse(data);
  31. }catch(e){
  32. alert("填写格式错误");return;
  33. }
  34. var d = new Date();
  35. d.setFullYear(d.getFullYear()+1);
  36. localStorage.customEmotion = d.getTime() +"|"+ data;
  37. }else{
  38. localStorage.customEmotion = undefined;
  39. }
  40. $('.s_tab_btn[data-type="custom"]').click();
  41. close();
  42. }
  43. function close(){
  44. $(".dialogJshadow").remove();
  45. }
  46. function a(){
  47. if($(".j_add_emotion").length){
  48. $(".j_add_emotion").removeClass("j_add_emotion").addClass("custom_add_emotion").html("修改");
  49. $(".custom_add_emotion").click(function(){
  50. var dialog = '<div class="dialogJ dialogJfix dialogJshadow ui-draggable" style="z-index: 50003; width: 680px; left: 372.5px; top: 122.5px;">\
  51. <div class="uiDialogWrapper">\
  52. <div class="dialogJtitle" style="-moz-user-select: none;-webkit-user-select:none;cursor: default;">\
  53. <span class="dialogJtxt">批量插入自定义表情</span>\
  54. <a title="关闭本窗口" class="dialogJclose" href="javascript:void(0)">&nbsp;</a>\
  55. </div>\
  56. <div class="dialogJcontent">\
  57. <div id="dialogJbody" class="dialogJbody" style="height: 460px;">\
  58. <div>\
  59. <div class="l_netpic_container">\
  60. <p>属性介绍:</p>\
  61. <span style="margin-left: 40px;color:red">title : 表情描述</span>\
  62. <span style="margin-left: 40px;color:red">url : 表情地址</span>\
  63. <span style="margin-left: 40px;color:red">thumbnail : 表情缩略图地址</span>\
  64. <textarea rows="20" id="add_emotion_text" style="width: 656px;resize:none"></textarea>\
  65. <br />\
  66. </div>\
  67. <div style="width: 678px;" class="i_layer_bottom">\
  68. <div class="i_layer_btn"><a href="javascript:void(0)" style="float:left;margin-right:10px;" class="ui_btn ui_btn_m">\
  69. <span><em>确 定</em></span></a><a href="javascript:void(0)" style="float:left" class="ui_btn ui_btn_sub_m"><span><em>取 消</em></span></a></div>\
  70. </div>\
  71. </div>\
  72. </div>\
  73. </div>\
  74. </div>\
  75. </div>';
  76. $("body").append(dialog);
  77. $(".dialogJclose").click(close);
  78. $("#add_emotion_text").html(loadText()).attr("value",loadText());
  79. $(".i_layer_bottom .i_layer_btn").click(save);
  80. $(".i_layer_bottom .ui_btn_sub_m").click(close);
  81. })
  82. }else{
  83. setTimeout(a,100);
  84. }
  85. }
  86.  
  87.  
  88. (function _init(){
  89. if($('.edui-btn.edui-btn-emotion').length){
  90. $('.edui-btn.edui-btn-emotion').click(a);
  91. }
  92. else{
  93. setTimeout(_init,100);
  94. }
  95. })();
  96.