// ==UserScript== // @name bgmnote // @namespace https://github.com/hentaiPanda // @description 简易备注 // @author niR // @version 0.0.1 // @license MIT License // @encoding utf-8 // @require http://code.jquery.com/jquery-2.1.1.js // @require http://code.jquery.com/ui/1.11.0/jquery-ui.js // @grant GM_getValue // @grant GM_setValue // @include http://bangumi.tv/group/topic/* // @include http://bgm.tv/group/topic/* // @include http://chii.in/group/topic/* // @include http://bangumi.tv/subject/topic/* // @include http://bgm.tv/subject/topic/* // @include http://chii.in/subject/topic/* // @include http://bangumi.tv/rakuen/topic/group/* // @include http://bgm.tv/rakuen/topic/group/* // @include http://chii.in/rakuen/topic/group/* // @include http://bangumi.tv/rakuen/topic/ep/* // @include http://bgm.tv/rakuen/topic/ep/* // @include http://chii.in/rakuen/topic/ep/* // @include http://bangumi.tv/blog/* // @include http://bgm.tv/blog/* // @include http://chii.in/blog/* // @include http://bangumi.tv/ep/* // @include http://bgm.tv/ep/* // @include http://chii.in/user/* // @include http://bangumi.tv/user/* // @include http://bgm.tv/user/* // @exclude http://chii.in/user/*/* // @exclude http://bangumi.tv/user/*/* // @exclude http://bgm.tv/user/*/* // @downloadURL none // ==/UserScript== var addBtn, addNotes, appendStyle, confirmHiding, getVal, hideNote, main, replaceNlc, showNote, updateNote; getVal = function() { var userlink, val; userlink = $('.user_box > a.avatar').attr('href'); val = GM_getValue(userlink, ''); return val; }; updateNote = function() { var userlink, val; val = $('#bgmnote textarea').val(); userlink = $('.user_box > a.avatar').attr('href'); GM_setValue(userlink, val); return hideNote(); }; confirmHiding = function() { var answer, new_val, val; val = getVal(); new_val = $('#bgmnote textarea').val(); if (val === new_val) { return hideNote(); } else { answer = confirm('备注似乎已经被更改,是否保存更改?'); if (answer) { return updateNote(); } else { return hideNote(); } } }; showNote = function() { var ui, val; console.log('This is showNote'); ui = $('#user_home .inner > p.tip').last(); ui.after('
   取消
'); val = getVal(); $('#bgmnote textarea').val(val); $('body').off('click.show_n'); $('body').on('click.textarea', '#bgmnotebtn', confirmHiding); $('body').on('click.textarea', '#cancelbtn', hideNote); return $('body').on('click.textarea', '#updatenote', updateNote); }; hideNote = function() { $('body').off('click.textarea'); $('#bgmnote').remove(); return $('body').on('click.show_n', '#bgmnotebtn', showNote); }; addBtn = function() { var new_btn, rr; rr = $('div.rr'); new_btn = '备注'; rr.html(rr.html() + new_btn); return $('body').on('click.show_n', '#bgmnotebtn', showNote); }; addNotes = function() { return $('a.avatar').each(function() { var note, userlink; if (this.parentNode.id.indexOf('post_') !== 0) { return 0; } userlink = this.getAttribute('href'); note = GM_getValue(userlink, ''); return this.setAttribute('title', note); }); }; replaceNlc = function(str) { var new_str; new_str = str.replace(/(>|^)([^<]*)\n([^>]*)(<|$)/g, function(s) { return s.replace(/\n/g, '
'); }); return new_str; }; appendStyle = function() { return $('head').append(''); }; main = function() { if (location.href.indexOf('user') > 0) { return addBtn(); } else { appendStyle(); addNotes(); return $('a.avatar').tooltip({ track: true, items: '[title]', content: function() { return replaceNlc(this.title); } }); } }; main();