// ==UserScript== // @name 云养宠物 // @version 2.0.1 // @description 在网页的右下角挂一个你喜欢的宠物咯 // @match * // @include * // @exclude https://juejin.cn/editor/drafts/* // @run-at document-end // @icon https://img2.baidu.com/it/u=4226010475,2406859093&fm=26&fmt=auto // @require https://code.jquery.com/jquery-3.1.1.min.js // @namespace http://www.touch-fish.com/bin/1 // @grant GM.setValue // @grant GM.getValue // @downloadURL https://update.greasyfork.icu/scripts/435384/%E4%BA%91%E5%85%BB%E5%AE%A0%E7%89%A9.user.js // @updateURL https://update.greasyfork.icu/scripts/435384/%E4%BA%91%E5%85%BB%E5%AE%A0%E7%89%A9.meta.js // ==/UserScript== { let defaultHTML = ` CSS睡猫
`; let html = `
`; console.log('test') let config = function() { let cache = JSON.parse(unsafeWindow.localStorage.touchFishDatas || null); if (cache == null) { cache = {}; cache['currUse'] = 'sleepCat'; cache.resource = {}; cache.resource['sleepCat'] = defaultHTML; updateLocalStorage(); } function updateLocalStorage() { unsafeWindow.localStorage.touchFishDatas = JSON.stringify(cache); } return { add(key, html) { cache.resource[key] = html; updateLocalStorage(); }, remove(key) { delete cache.resource[key]; updateLocalStorage(); }, change(key) { cache['currUse'] = key; changeHTML(cache.resource[key]); updateLocalStorage(); }, curr() { return cache.resource[cache['currUse']]; }, next() { let keys = Object.keys(cache.resource); let i = keys.indexOf(cache['currUse']); return cache.resource[keys[(i + 1) % keys.length]]; }, update(old, newK, html) { delete cache.resource[old]; cache.resource[newK] = html; updateLocalStorage(); }, resource() { return cache.resource; }, currKey(){ return cache['currUse']; } } }() $('body').prepend(html) $('head').append(``) let delayFunc = function() { let time; return { delay(func, t = 1200) { window.clearTimeout(time); time = setTimeout(() => func(), t); } } }(); $('.list').click(function() { let rols = `
`; let html = `
ADD
`; $('body').prepend(html); { let rtime; // 定时器交互 $('.tf-m-page').mouseleave(function() { rtime = setTimeout(() => $('.tf-m-page').remove(), 600) }).mouseenter(function() { window.clearTimeout(rtime) }); } $('.tf-m-page').on('input propertychange', 'input', function() { console.log('inpu') let $t = $(this).parent().find('input'); let old = $($t[0]).attr('old'), newK = $($t[0]).val(), h = $($t[1]).val(); delayFunc.delay(() => { config.update(old, newK, h); }) }).on('click', 'input[name="del"]', function() { $(this).parent().remove(); config.remove($(this).prev('[name="key"]').val()) }).on('click', 'input[name="useThis"]', function() { if ($(this).hasClass('tf-btn-use')) { return false; } $('.tf-list input[name="useThis"]').removeClass('tf-btn-use'); $(this).addClass('tf-btn-use'); config.change($(this).prev().prev().val()) }); $('.tf-btn-add').click(function() { $(this).parent().append(rols); }) // 初始化表单数据 Object.keys(config.resource()).forEach(k => { $('.tf-m-page').append(rols); let $input = $('.tf-m-page>.tf-list:last>input'); $($input[0]).attr('old', k).val(k); $($input[1]).val(config.resource()[k]); }) // 并选中当前的 $(`input[old="${config.currKey()}"]`).next().next().addClass('tf-btn-use') }) $('.change').click(function() { console.log('change'); changeHTML(config.next()); }) changeHTML(config.curr()); $('.touch-fish-toolbar').hide() $('.touch-fish').mouseover(function() { $('.touch-fish-toolbar').show(); }).mouseout(function() { $('.touch-fish-toolbar').hide() }); function changeHTML(html) { $('iframe[class="showHtml"]').contents().find('html').empty().append(html); } }