// ==UserScript==
// @name HKGalden Quote Folder
// @namespace https://userscripts.org/scripts/show/406097
// @description 縮短引用、縮小引用內圖片
// @author HKGalden 小磁怪
// @license MIT License
// @include https://hkgalden.com/view/*
// @include http://hkgalden.com/view/*
// @version 140725
// @icon https://hkgalden.com/favicon.ico
// @grant none
// @downloadURL none
// ==/UserScript==
/* ********* 更新記錄 *********
版本140725
- 沒有更新
版本140310
- 修復一個會令「快速引用」不能正常彈出的BUG
版本140309
- 改善程式碼
- 以圖示取代原有的文字按鈕
- 在所有引用層加入暫時縮短功能
版本140307-1
- 走位修正
*************************** */
/*jslint browser: true, devel: true, plusplus: true, es5: true, white: true */
/*jshint browser: true, devel: true, jquery: true, multistr: true, globalstrict: true */
/*global Storage, $*/
'use strict';
var qf_version = '140725';
//載入設定
var show_level, img_height, have_storage, tmp;
have_storage = (Storage !== undefined);
if (have_storage) {
tmp = localStorage.getItem('qf_settings_show_level');
if (!tmp) {
localStorage.setItem('qf_settings_show_level', 3);
show_level = 3;
} else {
show_level = parseInt(tmp, 10);
console.log('HKG Quote Folder : localStorage Quote Level = ' + show_level);
}
tmp = localStorage.getItem('qf_settings_img_height');
if (!tmp) {
localStorage.setItem('qf_settings_img_height', 150);
img_height = 150;
} else {
img_height = parseInt(tmp, 10);
console.log('HKG Quote Folder : localStorage Image Max Height = ' + img_height);
}
} else {
show_level = 3;
img_height = 150;
console.log('HKG Quote Folder : No localStorage support');
}
//判斷A<=x<=B的簡便方法
//http://indisnip.wordpress.com/2010/08/26/quicktip-check-if-a-number-is-between-two-numbers/
Number.prototype.between = function (first, last) {
return (first < last ? this >= first && this <= last : this >= last && this <= first);
};
$(function () {
//修正Firefox按鈕虛線外框問題,此項CSS無法透過jQuery.fn.css方法添加
//http://www.karlrixon.co.uk/writing/remove-button-focus-outline-using-css/
$('head').append(' \
');
//圖示
//Tango Icon Library | https://www.iconfinder.com/search/?q=iconset:tango-icon-library
var icon_plus = 'url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABmJLR0QA/wD/AP+gvaeTAAABzklEQVRIie2UvWuTURTGf+fNR41iRWxV/FgU3QQXVxEcFJyEDo6dHATFzdEU/AMsrh10EAQt/QvaDg6uOpRu6pDUxqavxIbqmzf3PA5JNNFoXkFBpA/c5d5zz/Oc+5xzYQf/PSxr4PlbTx9Gke0CMClZnp2aBtOoe/msBFcvnL5y8tjEBMDrSn1zef+MUebPEWAQNxMEo7P2IfqNWAAkCO5/h0ACZODZixj6RBdvzz8qjOVKg7tWEIYANytcSs7OcWfhK1H6OYSl2anr3+ca2kX3F15tnDjaMVQIZLhE3EyRYN/uPC5DEi4hweqbWu3e9LnDGSqQJa2XXom3QR1DJSN4J1EaYHMrpR1E20UIIjh82EqGGvMjQXnG4uZlL5RKyCGIrkrjXZzgwMHxIi4RXLg6MR8/tUJGgrt6cfPZY8tVi/3bZ04dumbFvZMSVNc36qtv3z8xfRs0dyXDCDJP8o0Hz6s2Nn5EgtZ2Y22usXSccnlkv2ZpUwNy7o4ELnAXrKxkEvezSY6AXPc8B0TtICuoZ7gbi4t7gBRoAwHIaPIgQW/lK2uxTR5I111Srd6ISNMCg7/G0F/kV2VGXQFR3+rFq6u4p7w9LPkO/g18ATeq4QJygwMsAAAAAElFTkSuQmCC)';
//FS Icons Ubuntu | https://www.iconfinder.com/search/?q=iconset:fs-icons-ubuntu-by-franksouza-
var icon_minus = 'url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAADhSURBVDiN7dRBSgNBFITh/3WcEXSrLlWI5/FArryA9/EOHkDwAAaUKEJIGKe7yoUG02QUN9nI1O5R3R80NC9ss4uknagjPMKD2dscZjeXR23y/vaxZTWtBqoSjc6ubmeDcDu9uMvz53MwCWPrs/ABWGDAorEJjGSiNUUC0ioiTmwvtuB+/lL6h3uaScLx8zPXVQJssEznVHkVnLNQV/BEv8KbsUHFmFTdqOE+s+wyXQqCv8nGFEGmVB+hgh+fXq/fDo9PkbAxCL62lEohHBbiuwdJgHBEBt7XVozbbYT/AfwBNxB4sYl2bPoAAAAASUVORK5CYII=)';
//摺疊按鈕
$('head').append('');
//根據顯示層數產生Selector
function quote_selector(n) {
var i, r = 'div.ctn';
for (i = 1; i <= show_level; i++) {
r += ' > blockquote' + (n===true?' > div':'');
}
return r;
}
/* 縮短引用 (舊版本方法)
function mod_quote() {
$(quote_selector()).each(function (i) {
if (!$(this).hasClass('qf_quote_mod')) {
$(this)
.hide()
.addClass('qf_quote_mod qf_quote_' + i)
.css({
'border-style' : 'dotted',
'border-width' : '1px',
'padding' : '5px 5px 5px 5px'
})
.before('
');
$('.qf_btn_' + i)
.css({
'cursor' : 'pointer',
'outline' : 'none'
})
.click(function () {
$($(this).prop('name')).toggle();
$(this).html($($(this).prop('name')).is(':visible') ? '縮短引用' : '展開引用');
})
.hover(function () {
$(this).css('text-shadow', '0 0 0 transparent, 0 0 0 rgba(0,0,0,0.7)');
}, function () {
$(this).css('text-shadow', '0 0 0 transparent, 0 0 1px rgba(0,0,0,0.7)');
});
}
});
}
*/
//產生摺疊按鈕
function create_fold_btn() {
$('div.ctn').find('blockquote')
.each(function (index) {
if ((!$(this).hasClass('qf_quote_mod'))) {
$(this)
.addClass('qf_quote_mod qf_quote_' + index)
.wrapInner('