mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-11-02 22:33:56 +08:00
update 2026-10-27 11:22:48
This commit is contained in:
1 parent
a4d6470641
commit
63a5dffe55
4907 files changed
+2036791
No files matched your search
+2
@@ -0,0 +1,2 @@
|
||||
/*! Sortable 1.15.7 - MIT | git://github.com/SortableJS/Sortable.git */
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Sortable=e()}(this,function(){"use strict";function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function i(t,e,n){return(e=function(t){t=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0===n)return("string"===e?String:Number)(t);e=n.call(t,e||"default");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==typeof t?t:t+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function a(){return(a=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n,o=arguments[e];for(n in o)!{}.hasOwnProperty.call(o,n)||(t[n]=o[n])}return t}).apply(null,arguments)}function r(e,t){var n,o=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),o.push.apply(o,n)),o}function I(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach(function(t){i(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function l(t,e){if(null==t)return{};var n,o=function(t,e){if(null==t)return{};var n,o={};for(n in t)if({}.hasOwnProperty.call(t,n)){if(-1!==e.indexOf(n))continue;o[n]=t[n]}return o}(t,e);if(Object.getOwnPropertySymbols)for(var i=Object.getOwnPropertySymbols(t),r=0;r<i.length;r++)n=i[r],-1===e.indexOf(n)&&{}.propertyIsEnumerable.call(t,n)&&(o[n]=t[n]);return o}function e(t){return function(t){if(Array.isArray(t))return o(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return o(t,e);var n={}.toString.call(t).slice(8,-1);return"Map"===(n="Object"===n&&t.constructor?t.constructor.name:n)||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(t){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function t(t){if("undefined"!=typeof window&&window.navigator)return!!navigator.userAgent.match(t)}var y=t(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),w=t(/Edge/i),c=t(/firefox/i),u=t(/safari/i)&&!t(/chrome/i)&&!t(/android/i),d=t(/iP(ad|od|hone)/i),n=t(/chrome/i)&&t(/android/i),h={capture:!1,passive:!1};function f(t,e,n){t.addEventListener(e,n,!y&&h)}function p(t,e,n){t.removeEventListener(e,n,!y&&h)}function g(t,e){if(e&&(">"===e[0]&&(e=e.substring(1)),t))try{if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e);if(t.webkitMatchesSelector)return t.webkitMatchesSelector(e)}catch(t){return}}function m(t){return t.host&&t!==document&&t.host.nodeType&&t.host!==t?t.host:t.parentNode}function P(t,e,n,o){if(t){n=n||document;do{if(null!=e&&(">"!==e[0]||t.parentNode===n)&&g(t,e)||o&&t===n)return t}while(t!==n&&(t=m(t)))}return null}var v,b=/\s+/g;function k(t,e,n){var o;t&&e&&(t.classList?t.classList[n?"add":"remove"](e):(o=(" "+t.className+" ").replace(b," ").replace(" "+e+" "," "),t.className=(o+(n?" "+e:"")).replace(b," ")))}function R(t,e,n){var o=t&&t.style;if(o){if(void 0===n)return document.defaultView&&document.defaultView.getComputedStyle?n=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(n=t.currentStyle),void 0===e?n:n[e];o[e=!(e in o||-1!==e.indexOf("webkit"))?"-webkit-"+e:e]=n+("string"==typeof n?"":"px")}}function D(t,e){var n="";if("string"==typeof t)n=t;else do{var o=R(t,"transform")}while(o&&"none"!==o&&(n=o+" "+n),!e&&(t=t.parentNode));var i=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix||window.MSCSSMatrix;return i&&new i(n)}function E(t,e,n){if(t){var o=t.getElementsByTagName(e),i=0,r=o.length;if(n)for(;i<r;i++)n(o[i],i);return o}return[]}function O(){var t=document.scrollingElement;return t||document.documentElement}function X(t,e,n,o,i){if(t.getBoundingClientRect||t===window){var r,a,l,s,c,u,d=t!==window&&t.parentNode&&t!==O()?(a=(r=t.getBoundingClientRect()).top,l=r.left,s=r.bottom,c=r.right,u=r.height,r.width):(l=a=0,s=window.innerHeight,c=window.innerWidth,u=window.innerHeight,window.innerWidth);if((e||n)&&t!==window&&(i=i||t.parentNode,!y))do{if(i&&i.getBoundingClientRect&&("none"!==R(i,"transform")||n&&"static"!==R(i,"position"))){var h=i.getBouLine truncated
|
||||
@@ -0,0 +1,50 @@
|
||||
function is_json(str) {
|
||||
try {
|
||||
const result = JSON.parse(str);
|
||||
return typeof result === 'object' && result !== null;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function is_timehhmm(str) {
|
||||
const match = String(str).match(/^(\d?\d):(\d\d)$/);
|
||||
if (match) {
|
||||
const hour = parseInt(match[1], 10);
|
||||
const minute = parseInt(match[2], 10);
|
||||
if (hour >= 0 && hour <= 23 && minute >= 0 && minute <= 59) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof cbi_validators !== 'undefined' && cbi_validators !== null) {
|
||||
cbi_validators['base64'] = function() {
|
||||
return isBase64(this);
|
||||
}
|
||||
cbi_validators['json'] = function() {
|
||||
return is_json(this);
|
||||
}
|
||||
cbi_validators['timehhmm'] = function() {
|
||||
return is_timehhmm(this);
|
||||
}
|
||||
cbi_validators['uuid'] = function() {
|
||||
return isUUID(this);
|
||||
}
|
||||
} else {
|
||||
L.require('validation').then(function(validation) {
|
||||
validation.types['base64'] = function() {
|
||||
return this.assert(isBase64(this.value), _('Must be Base64 text!'));
|
||||
}
|
||||
validation.types['json'] = function() {
|
||||
return this.assert(is_json(this.value), _('Must be JSON text!'));
|
||||
}
|
||||
validation.types['timehhmm'] = function() {
|
||||
return this.assert(is_timehhmm(this.value), _('valid time (hh:mm)'));
|
||||
}
|
||||
validation.types['uuid'] = function() {
|
||||
return this.assert(isUUID(this.value), _('Must be UUID format!'));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
function arraysEqual(a, b) {
|
||||
if (a === b) return true;
|
||||
if (a == null || b == null) return false;
|
||||
if (a.length !== b.length) return false;
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (a[i] !== b[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function isBase64(str) {
|
||||
const base64Regex = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/;
|
||||
return base64Regex.test(str);
|
||||
}
|
||||
|
||||
function decodeIfBase64(str) {
|
||||
try {
|
||||
let s = str.replace(/-/g, '+').replace(/_/g, '/');
|
||||
while (s.length % 4) s += '=';
|
||||
const decoded = decodeURIComponent(
|
||||
atob(s).split('').map(c =>
|
||||
'%' + c.charCodeAt(0).toString(16).padStart(2, '0')
|
||||
).join('')
|
||||
);
|
||||
if (btoa(unescape(encodeURIComponent(decoded))).replace(/=+$/, '') === s.replace(/=+$/, '')) {
|
||||
return decoded;
|
||||
}
|
||||
} catch (e) {}
|
||||
return str;
|
||||
}
|
||||
|
||||
function isUUID(str) {
|
||||
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||
return uuidRegex.test(str);
|
||||
}
|
||||
|
||||
function waitForElement(selector, callback) {
|
||||
const el = document.querySelector(selector);
|
||||
if (el) return callback(el);
|
||||
const observer = new MutationObserver(() => {
|
||||
const el = document.querySelector(selector);
|
||||
if (el) {
|
||||
observer.disconnect();
|
||||
callback(el);
|
||||
}
|
||||
});
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
function waitForElementId(id, callback) {
|
||||
waitForElement("#" + CSS.escape(id), callback);
|
||||
//waitForElement('[id="' + id + '"]', callback);
|
||||
}
|
||||
|
||||
function get_current_url() {
|
||||
return window.location.origin + window.location.pathname;
|
||||
}
|
||||
|
||||
function getOption(config, section, opt) {
|
||||
let obj;
|
||||
const id = `cbid.${config}.${section}.${opt}`;
|
||||
obj = document.getElementsByName(id)[0] || document.getElementById(id);
|
||||
if (obj) {
|
||||
//lua luci combobox
|
||||
const combobox = document.getElementById('cbi.combobox.' + id);
|
||||
if (combobox) {
|
||||
obj.combobox = combobox;
|
||||
}
|
||||
return obj;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,775 @@
|
||||
/*
|
||||
* Click-to-sort headers and a per-group filter bar for the node list.
|
||||
*
|
||||
* Sort reorders rows inside one group table and calls set_order(), the same
|
||||
* path as drag-and-drop and To Top. Nothing is written until Save & Apply.
|
||||
*
|
||||
* A filter only toggles the pw-row-hidden class. Rows stay in the form, so
|
||||
* Save & Apply still posts every node and the full group.order value.
|
||||
*
|
||||
* Translated strings are read from #pw2-nodesort-i18n (the node list template).
|
||||
* The template calls init() once, then enhanceAll() after loadNodeList()
|
||||
* has built the group tables.
|
||||
*
|
||||
* auto_detection_time is a top-level let in the template, not a window
|
||||
* property. It is read by name so rows are not moved while automatic Ping
|
||||
* or TCPing is still writing results by row position.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var COLUMNS = {
|
||||
'pw-remark': 'name',
|
||||
'pw-ping': 'ping',
|
||||
'pw-tcping': 'tcping',
|
||||
'pw-urltest': 'urltest'
|
||||
};
|
||||
/* sub controls drawn inside the Remarks header: [sort key, label key or symbol, title key] */
|
||||
var NAME_EXTRA = [
|
||||
['type', 'type', 'typeHint'],
|
||||
['addr', 'addr', 'addrHint'],
|
||||
['orig', '\u21BA', 'origHint']
|
||||
];
|
||||
|
||||
var state = {
|
||||
app: 'passwall2',
|
||||
root: null,
|
||||
text: {},
|
||||
bound: false
|
||||
};
|
||||
var searchTimer = null;
|
||||
|
||||
function T(key) {
|
||||
var value = state.text[key];
|
||||
return (value == null || value === '') ? key : value;
|
||||
}
|
||||
|
||||
function readText(box) {
|
||||
var text = {};
|
||||
var spans = box.querySelectorAll('[data-k]');
|
||||
for (var i = 0; i < spans.length; i++)
|
||||
text[spans[i].getAttribute('data-k')] = spans[i].textContent;
|
||||
return text;
|
||||
}
|
||||
|
||||
var collator = null;
|
||||
function prepareCollator() {
|
||||
var lang = document.documentElement.lang || (navigator.language || '');
|
||||
try {
|
||||
collator = (window.Intl && Intl.Collator) ? new Intl.Collator(lang || undefined, { numeric: true, sensitivity: 'base' }) : null;
|
||||
} catch (e) {
|
||||
collator = null;
|
||||
}
|
||||
}
|
||||
|
||||
function cmpText(a, b) {
|
||||
if (collator)
|
||||
return collator.compare(a, b);
|
||||
return a < b ? -1 : (a > b ? 1 : 0);
|
||||
}
|
||||
|
||||
/* "123 ms", "12.5 ms", "1.2 s" -> milliseconds. Timeout, Error, ---, Test stay null. */
|
||||
function parseLatency(text) {
|
||||
var t = String(text || '').replace(/\s+/g, ' ').trim();
|
||||
var m = /^(\d+(?:[.,]\d+)?)\s*(ms|s)?$/i.exec(t);
|
||||
if (!m)
|
||||
return null;
|
||||
var v = parseFloat(m[1].replace(',', '.'));
|
||||
if (isNaN(v))
|
||||
return null;
|
||||
if (m[2] && /^s$/i.test(m[2]))
|
||||
v *= 1000;
|
||||
return v;
|
||||
}
|
||||
|
||||
function hiddenVal(id, opt) {
|
||||
var el = document.getElementById('cbid.' + state.app + '.' + id + '.' + opt);
|
||||
return el && el.value != null ? String(el.value).trim() : '';
|
||||
}
|
||||
|
||||
function cellsOf(tr) {
|
||||
var out = [];
|
||||
for (var i = 0; i < tr.children.length; i++) {
|
||||
var tag = tr.children[i].tagName;
|
||||
if (tag === 'TD' || tag === 'TH')
|
||||
out.push(tr.children[i]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
var wordSplit;
|
||||
try {
|
||||
wordSplit = new RegExp('[^\\p{L}\\p{N}]+', 'u');
|
||||
} catch (e) {
|
||||
wordSplit = /[\s.,;:!?|\/\\()\[\]{}<>"'`~@#$%^&*=+_-]+/;
|
||||
}
|
||||
|
||||
function wordsOf(text) {
|
||||
var seen = {};
|
||||
var out = [];
|
||||
var parts = String(text || '').split(wordSplit);
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
var w = parts[i];
|
||||
if (w.length < 2 || /^\d+$/.test(w))
|
||||
continue;
|
||||
var k = w.toLowerCase();
|
||||
if (!seen[k]) {
|
||||
seen[k] = 1;
|
||||
out.push(w);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function infoOf(table) {
|
||||
var prefix = 'cbi-' + state.app + '-nodes-';
|
||||
var id = table && table.id ? table.id : '';
|
||||
if (id.indexOf(prefix) !== 0 || id.slice(-6) !== '-table')
|
||||
return null;
|
||||
return { group: id.slice(prefix.length, -6) };
|
||||
}
|
||||
|
||||
function rowId(tr) {
|
||||
var prefix = 'cbi-' + state.app + '-';
|
||||
return tr.id.indexOf(prefix) === 0 ? tr.id.substring(prefix.length) : tr.id;
|
||||
}
|
||||
|
||||
function bodyOf(table) {
|
||||
return table.querySelector('tbody') || table;
|
||||
}
|
||||
|
||||
function dataRows(table) {
|
||||
var body = bodyOf(table);
|
||||
var out = [];
|
||||
for (var i = 0; i < body.children.length; i++) {
|
||||
var tr = body.children[i];
|
||||
if (tr.tagName === 'TR' && tr.classList.contains('cbi-section-table-row') && !tr.classList.contains('placeholder'))
|
||||
out.push(tr);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function colIndexMap(table) {
|
||||
var rows = dataRows(table);
|
||||
var map = {};
|
||||
if (!rows.length)
|
||||
return map;
|
||||
var cells = cellsOf(rows[0]);
|
||||
for (var i = 0; i < cells.length; i++) {
|
||||
for (var cls in COLUMNS) {
|
||||
if (cells[i].classList.contains(cls))
|
||||
map[COLUMNS[cls]] = i;
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
function typeOf(tr, cols) {
|
||||
var cell = cellsOf(tr)[cols.name];
|
||||
var text = cell ? cell.textContent.replace(/\s+/g, ' ').trim() : '';
|
||||
var i = text.indexOf('\uFF1A');
|
||||
if (i < 0)
|
||||
i = text.indexOf(':');
|
||||
return (i < 0 ? '' : text.slice(0, i)).replace(/\s+Realm$/, '').trim();
|
||||
}
|
||||
|
||||
function sortKey(tr, key, cols) {
|
||||
var id = rowId(tr);
|
||||
var cell;
|
||||
if (key === 'name')
|
||||
return hiddenVal(id, 'remarks') || ((cellsOf(tr)[cols.name] || {}).textContent || '').trim();
|
||||
if (key === 'type')
|
||||
return typeOf(tr, cols) + '\u0000' + hiddenVal(id, 'remarks');
|
||||
if (key === 'addr') {
|
||||
var address = hiddenVal(id, 'address');
|
||||
if (!address)
|
||||
return null;
|
||||
return address + '\u0000' + ('00000' + hiddenVal(id, 'port')).slice(-5);
|
||||
}
|
||||
cell = cellsOf(tr)[cols[key]];
|
||||
return cell ? parseLatency(cell.textContent) : null;
|
||||
}
|
||||
|
||||
function detectionMode() {
|
||||
try {
|
||||
if (typeof auto_detection_time === 'undefined')
|
||||
return null;
|
||||
return auto_detection_time;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/* { inflight: requests still running, left: cells still waiting for a result } */
|
||||
function pingBusy() {
|
||||
var mode = detectionMode();
|
||||
var inflight = 0;
|
||||
var left = 0;
|
||||
if (mode !== 'icmp' && mode !== 'tcping')
|
||||
return { inflight: 0, left: 0 };
|
||||
var list = window.ajax && window.ajax.list;
|
||||
if (list && list.length) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
if (list[i].readyState > 0 && list[i].readyState < 4)
|
||||
inflight++;
|
||||
}
|
||||
}
|
||||
if (!state.root)
|
||||
return { inflight: inflight, left: 0 };
|
||||
var spans = state.root.getElementsByClassName(mode === 'tcping' ? 'tcping_value' : 'ping_value');
|
||||
for (var s = 0; s < spans.length; s++) {
|
||||
var id = spans[s].getAttribute('cbiid');
|
||||
if (!id || spans[s].textContent.trim() !== '---')
|
||||
continue;
|
||||
var full = null;
|
||||
if (typeof window.get_address_full === 'function')
|
||||
full = window.get_address_full(id);
|
||||
if (!full)
|
||||
full = { address: hiddenVal(id, 'address'), port: hiddenVal(id, 'port') };
|
||||
if (full.address && (mode === 'icmp' || full.port))
|
||||
left++;
|
||||
}
|
||||
return { inflight: inflight, left: left };
|
||||
}
|
||||
|
||||
function note(table, text) {
|
||||
var id = 'pw-note-' + table.id;
|
||||
var el = document.getElementById(id);
|
||||
if (!text) {
|
||||
if (el && el.parentNode)
|
||||
el.parentNode.removeChild(el);
|
||||
return;
|
||||
}
|
||||
if (!el) {
|
||||
el = document.createElement('div');
|
||||
el.id = id;
|
||||
el.className = 'pw-sort-note';
|
||||
table.parentNode.insertBefore(el, table);
|
||||
}
|
||||
el.textContent = text;
|
||||
}
|
||||
|
||||
function setIndicator(table, th, sub, key, dir) {
|
||||
var arrows = table.querySelectorAll('.pw-sort-arrow');
|
||||
var subs = table.querySelectorAll('.pw-sort-sub');
|
||||
var headers = table.querySelectorAll('th[data-pw-sort]');
|
||||
var i;
|
||||
for (i = 0; i < arrows.length; i++)
|
||||
arrows[i].textContent = '';
|
||||
for (i = 0; i < subs.length; i++)
|
||||
subs[i].classList.remove('pw-sort-active');
|
||||
for (i = 0; i < headers.length; i++) {
|
||||
if (headers[i] !== th) {
|
||||
delete headers[i].dataset.pwDir;
|
||||
delete headers[i].dataset.pwKey;
|
||||
}
|
||||
}
|
||||
var arrow = th.querySelector('.pw-sort-arrow');
|
||||
if (arrow && key !== 'orig' && !sub)
|
||||
arrow.textContent = dir === 'desc' ? '\u25BC' : '\u25B2';
|
||||
if (sub && key !== 'orig')
|
||||
sub.classList.add('pw-sort-active');
|
||||
}
|
||||
|
||||
function applyOrder(table, info, rows) {
|
||||
var body = bodyOf(table);
|
||||
var frag = document.createDocumentFragment();
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
rows[i].classList.remove('cbi-rowstyle-1', 'cbi-rowstyle-2');
|
||||
rows[i].classList.add('cbi-rowstyle-' + (i % 2 + 1));
|
||||
frag.appendChild(rows[i]);
|
||||
}
|
||||
body.appendChild(frag);
|
||||
if (typeof window.set_order === 'function')
|
||||
window.set_order(info.group);
|
||||
}
|
||||
|
||||
function doSort(table, th, sub, key) {
|
||||
var info = infoOf(table);
|
||||
var rows = dataRows(table);
|
||||
var dir = 'asc';
|
||||
if (!info || rows.length < 2)
|
||||
return;
|
||||
if (key === 'orig') {
|
||||
var pos = {};
|
||||
var orig = table.__pwOrig || [];
|
||||
for (var n = 0; n < orig.length; n++)
|
||||
pos[orig[n]] = n;
|
||||
rows.sort(function (a, b) {
|
||||
var pa = pos[rowId(a)];
|
||||
var pb = pos[rowId(b)];
|
||||
return (pa == null ? 1e9 : pa) - (pb == null ? 1e9 : pb);
|
||||
});
|
||||
delete th.dataset.pwDir;
|
||||
delete th.dataset.pwKey;
|
||||
} else {
|
||||
dir = (th.dataset.pwKey === key && th.dataset.pwDir === 'asc') ? 'desc' : 'asc';
|
||||
th.dataset.pwKey = key;
|
||||
th.dataset.pwDir = dir;
|
||||
var cols = colIndexMap(table);
|
||||
var sign = dir === 'desc' ? -1 : 1;
|
||||
var list = [];
|
||||
for (var i = 0; i < rows.length; i++)
|
||||
list.push({ tr: rows[i], i: i, k: sortKey(rows[i], key, cols) });
|
||||
list.sort(function (a, b) {
|
||||
var emptyA = (a.k === null || a.k === '');
|
||||
var emptyB = (b.k === null || b.k === '');
|
||||
if (emptyA || emptyB)
|
||||
return emptyA === emptyB ? a.i - b.i : (emptyA ? 1 : -1);
|
||||
var cmp = (typeof a.k === 'number' && typeof b.k === 'number') ? a.k - b.k : cmpText(String(a.k), String(b.k));
|
||||
return cmp !== 0 ? sign * cmp : a.i - b.i;
|
||||
});
|
||||
rows = [];
|
||||
for (var j = 0; j < list.length; j++)
|
||||
rows.push(list[j].tr);
|
||||
}
|
||||
applyOrder(table, info, rows);
|
||||
refreshFilter(table);
|
||||
setIndicator(table, th, sub, key, dir);
|
||||
note(table, key === 'orig' ? T('restored') : T('changed'));
|
||||
}
|
||||
|
||||
function requestSort(table, th, sub, key) {
|
||||
if (table.__pwWait) {
|
||||
clearInterval(table.__pwWait);
|
||||
table.__pwWait = null;
|
||||
}
|
||||
var st = pingBusy();
|
||||
if (!st.inflight && !st.left) {
|
||||
doSort(table, th, sub, key);
|
||||
return;
|
||||
}
|
||||
var started = Date.now();
|
||||
var idle = 0;
|
||||
note(table, T('wait').replace('%d', st.left || st.inflight));
|
||||
table.__pwWait = setInterval(function () {
|
||||
st = pingBusy();
|
||||
idle = st.inflight ? 0 : idle + 1;
|
||||
if ((!st.inflight && !st.left) || idle >= 6) {
|
||||
clearInterval(table.__pwWait);
|
||||
table.__pwWait = null;
|
||||
if (document.body.contains(table))
|
||||
doSort(table, th, sub, key);
|
||||
return;
|
||||
}
|
||||
if (Date.now() - started > 120000) {
|
||||
clearInterval(table.__pwWait);
|
||||
table.__pwWait = null;
|
||||
note(table, T('waitFail'));
|
||||
return;
|
||||
}
|
||||
note(table, T('wait').replace('%d', st.left || st.inflight));
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function enhance(table) {
|
||||
var info = infoOf(table);
|
||||
if (!info || table.__pwReady)
|
||||
return;
|
||||
var titles = table.querySelector('tr.cbi-section-table-titles');
|
||||
var rows = dataRows(table);
|
||||
if (!titles || !rows.length)
|
||||
return;
|
||||
var cols = colIndexMap(table);
|
||||
var headers = cellsOf(titles);
|
||||
table.__pwReady = true;
|
||||
table.__pwOrig = [];
|
||||
for (var r = 0; r < rows.length; r++)
|
||||
table.__pwOrig.push(rowId(rows[r]));
|
||||
for (var key in cols) {
|
||||
if (!Object.prototype.hasOwnProperty.call(cols, key))
|
||||
continue;
|
||||
var th = headers[cols[key]];
|
||||
if (!th || th.classList.contains('cbi-section-actions'))
|
||||
continue;
|
||||
th.setAttribute('data-pw-sort', key);
|
||||
th.title = T('hint');
|
||||
var arrow = document.createElement('span');
|
||||
arrow.className = 'pw-sort-arrow';
|
||||
th.appendChild(arrow);
|
||||
if (key !== 'name')
|
||||
continue;
|
||||
for (var s = 0; s < NAME_EXTRA.length; s++) {
|
||||
var spec = NAME_EXTRA[s];
|
||||
var sp = document.createElement('span');
|
||||
sp.className = 'pw-sort-sub';
|
||||
sp.setAttribute('data-pw-sort', spec[0]);
|
||||
sp.textContent = T(spec[1]);
|
||||
sp.title = T(spec[2]);
|
||||
th.appendChild(sp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function rowVisible(el) {
|
||||
var row = el && el.closest ? el.closest('tr') : null;
|
||||
return !row || !row.classList.contains('pw-row-hidden');
|
||||
}
|
||||
|
||||
function filterDefs(rows, cols) {
|
||||
return [
|
||||
{
|
||||
key: 'type',
|
||||
label: T('type'),
|
||||
multi: false,
|
||||
get: function (tr) { return typeOf(tr, cols); }
|
||||
},
|
||||
{
|
||||
key: 'word',
|
||||
label: T('fWord'),
|
||||
multi: true,
|
||||
minCount: 2,
|
||||
max: 40,
|
||||
get: function (tr) { return wordsOf(hiddenVal(rowId(tr), 'remarks')); }
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function searchText(tr, cols) {
|
||||
var id = rowId(tr);
|
||||
return [
|
||||
typeOf(tr, cols),
|
||||
hiddenVal(id, 'remarks'),
|
||||
hiddenVal(id, 'address') + ':' + hiddenVal(id, 'port')
|
||||
].join(' ');
|
||||
}
|
||||
|
||||
function collect(table) {
|
||||
var rows = dataRows(table);
|
||||
var cols = colIndexMap(table);
|
||||
var defs = rows.length >= 2 ? filterDefs(rows, cols) : [];
|
||||
var shown = [];
|
||||
for (var d = 0; d < defs.length; d++) {
|
||||
var def = defs[d];
|
||||
var counts = {};
|
||||
var labels = {};
|
||||
var vals = [];
|
||||
for (var r = 0; r < rows.length; r++) {
|
||||
var raw = def.get(rows[r]);
|
||||
var list = def.multi ? (raw || []) : [raw == null ? '' : String(raw)];
|
||||
var keys = [];
|
||||
for (var n = 0; n < list.length; n++) {
|
||||
var item = list[n];
|
||||
var k = def.multi ? String(item).toLowerCase() : String(item);
|
||||
counts[k] = (counts[k] || 0) + 1;
|
||||
if (!labels[k])
|
||||
labels[k] = {};
|
||||
labels[k][item] = (labels[k][item] || 0) + 1;
|
||||
keys.push(k);
|
||||
}
|
||||
vals.push(keys);
|
||||
}
|
||||
var opts = [];
|
||||
for (var k in counts) {
|
||||
if (!Object.prototype.hasOwnProperty.call(counts, k))
|
||||
continue;
|
||||
if (def.multi && (counts[k] < (def.minCount || 1) || counts[k] >= rows.length))
|
||||
continue;
|
||||
var best = '';
|
||||
var bestN = -1;
|
||||
for (var label in labels[k]) {
|
||||
if (labels[k][label] > bestN) {
|
||||
bestN = labels[k][label];
|
||||
best = label;
|
||||
}
|
||||
}
|
||||
opts.push({ v: k, label: best === '' ? T('empty') : best, n: counts[k] });
|
||||
}
|
||||
opts.sort(function (a, b) {
|
||||
if (def.multi && a.n !== b.n)
|
||||
return b.n - a.n;
|
||||
return cmpText(a.label, b.label);
|
||||
});
|
||||
if (def.max && opts.length > def.max)
|
||||
opts = opts.slice(0, def.max);
|
||||
var enough = def.multi ? opts.length >= 1 : opts.length >= 2;
|
||||
if (!enough)
|
||||
continue;
|
||||
def.vals = vals;
|
||||
def.opts = opts;
|
||||
shown.push(def);
|
||||
}
|
||||
var search = rows.length >= 2;
|
||||
var sig = String(rows.length) + (search ? 's' : '');
|
||||
for (var i = 0; i < shown.length; i++) {
|
||||
sig += '|' + shown[i].key + '=';
|
||||
for (var o = 0; o < shown[i].opts.length; o++)
|
||||
sig += shown[i].opts[o].v + ':' + shown[i].opts[o].n + ',';
|
||||
}
|
||||
return { rows: rows, cols: cols, defs: shown, search: search, sig: sig };
|
||||
}
|
||||
|
||||
function barId(table) {
|
||||
return 'pw-filter-' + table.id;
|
||||
}
|
||||
|
||||
function buildBar(table, collected) {
|
||||
var st = table.__pwF || (table.__pwF = { sel: {}, q: '' });
|
||||
var id = barId(table);
|
||||
var bar = document.getElementById(id);
|
||||
if (!bar) {
|
||||
bar = document.createElement('div');
|
||||
bar.id = id;
|
||||
bar.className = 'pw-filter';
|
||||
bar.title = T('filterHint');
|
||||
table.parentNode.insertBefore(bar, table);
|
||||
bar.__pwTable = table;
|
||||
}
|
||||
while (bar.firstChild)
|
||||
bar.removeChild(bar.firstChild);
|
||||
var head = document.createElement('span');
|
||||
head.textContent = T('filter');
|
||||
bar.appendChild(head);
|
||||
var keep = {};
|
||||
for (var d = 0; d < collected.defs.length; d++) {
|
||||
var def = collected.defs[d];
|
||||
var lab = document.createElement('label');
|
||||
var sel = document.createElement('select');
|
||||
lab.appendChild(document.createTextNode(def.label));
|
||||
sel.className = 'cbi-input-select';
|
||||
sel.setAttribute('data-pw-filter', def.key);
|
||||
var all = document.createElement('option');
|
||||
all.value = '';
|
||||
all.textContent = T('all') + ' (' + collected.rows.length + ')';
|
||||
sel.appendChild(all);
|
||||
for (var o = 0; o < def.opts.length; o++) {
|
||||
var op = document.createElement('option');
|
||||
op.value = 'v:' + def.opts[o].v;
|
||||
op.textContent = def.opts[o].label + ' (' + def.opts[o].n + ')';
|
||||
sel.appendChild(op);
|
||||
}
|
||||
var cur = st.sel[def.key] || '';
|
||||
var known = false;
|
||||
if (cur) {
|
||||
for (var c = 0; c < def.opts.length; c++) {
|
||||
if (('v:' + def.opts[c].v) === cur) {
|
||||
known = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!known)
|
||||
cur = '';
|
||||
sel.value = cur;
|
||||
if (cur)
|
||||
keep[def.key] = cur;
|
||||
lab.appendChild(sel);
|
||||
bar.appendChild(lab);
|
||||
}
|
||||
st.sel = keep;
|
||||
if (collected.search) {
|
||||
var input = document.createElement('input');
|
||||
input.type = 'search';
|
||||
input.className = 'cbi-input-text';
|
||||
input.placeholder = T('search');
|
||||
input.title = T('searchHint');
|
||||
input.autocomplete = 'off';
|
||||
input.setAttribute('data-pw-search', '1');
|
||||
input.value = st.q;
|
||||
bar.appendChild(input);
|
||||
} else {
|
||||
st.q = '';
|
||||
}
|
||||
var count = document.createElement('span');
|
||||
count.className = 'pw-filter-count';
|
||||
bar.appendChild(count);
|
||||
var reset = document.createElement('button');
|
||||
reset.type = 'button';
|
||||
reset.className = 'btn cbi-button';
|
||||
reset.setAttribute('data-pw-reset', '1');
|
||||
reset.textContent = T('reset');
|
||||
reset.title = T('resetHint');
|
||||
bar.appendChild(reset);
|
||||
return bar;
|
||||
}
|
||||
|
||||
function listHas(list, value) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
if (list[i] === value)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function applyFilter(table, collected, bar) {
|
||||
var st = table.__pwF || { sel: {}, q: '' };
|
||||
var q = String(st.q || '').toLowerCase().trim();
|
||||
var active = !!q;
|
||||
var shown = 0;
|
||||
var unchecked = false;
|
||||
var d;
|
||||
for (d = 0; d < collected.defs.length; d++) {
|
||||
if (st.sel[collected.defs[d].key])
|
||||
active = true;
|
||||
}
|
||||
for (var i = 0; i < collected.rows.length; i++) {
|
||||
var tr = collected.rows[i];
|
||||
var ok = true;
|
||||
for (d = 0; d < collected.defs.length; d++) {
|
||||
var sel = st.sel[collected.defs[d].key];
|
||||
if (ok && sel && !listHas(collected.defs[d].vals[i], sel.slice(2)))
|
||||
ok = false;
|
||||
}
|
||||
if (ok && q && searchText(tr, collected.cols).toLowerCase().indexOf(q) < 0)
|
||||
ok = false;
|
||||
if (ok !== !tr.classList.contains('pw-row-hidden'))
|
||||
tr.classList.toggle('pw-row-hidden', !ok);
|
||||
if (ok) {
|
||||
shown++;
|
||||
var want = 'cbi-rowstyle-' + ((shown - 1) % 2 + 1);
|
||||
var other = want === 'cbi-rowstyle-1' ? 'cbi-rowstyle-2' : 'cbi-rowstyle-1';
|
||||
if (!tr.classList.contains(want))
|
||||
tr.classList.add(want);
|
||||
if (tr.classList.contains(other))
|
||||
tr.classList.remove(other);
|
||||
} else {
|
||||
var cb = tr.querySelector('input.nodes_select');
|
||||
if (cb && cb.checked) {
|
||||
cb.checked = false;
|
||||
unchecked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (unchecked && typeof window.update_select_state === 'function')
|
||||
window.update_select_state();
|
||||
var count = bar.querySelector('.pw-filter-count');
|
||||
var txt = T('shown').replace('%s', shown).replace('%t', collected.rows.length);
|
||||
if (count && count.textContent !== txt)
|
||||
count.textContent = txt;
|
||||
if (bar.classList.contains('pw-filter-on') !== active)
|
||||
bar.classList.toggle('pw-filter-on', active);
|
||||
}
|
||||
|
||||
function removeBar(table) {
|
||||
var bar = document.getElementById(barId(table));
|
||||
if (bar && bar.parentNode)
|
||||
bar.parentNode.removeChild(bar);
|
||||
var rows = dataRows(table);
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
if (rows[i].classList.contains('pw-row-hidden'))
|
||||
rows[i].classList.remove('pw-row-hidden');
|
||||
}
|
||||
table.__pwSig = null;
|
||||
}
|
||||
|
||||
function refreshFilter(table) {
|
||||
if (!infoOf(table))
|
||||
return;
|
||||
var collected = collect(table);
|
||||
if (!collected.defs.length && !collected.search) {
|
||||
if (table.__pwSig)
|
||||
removeBar(table);
|
||||
return;
|
||||
}
|
||||
var bar = document.getElementById(barId(table));
|
||||
if (!bar || collected.sig !== table.__pwSig) {
|
||||
bar = buildBar(table, collected);
|
||||
table.__pwSig = collected.sig;
|
||||
}
|
||||
applyFilter(table, collected, bar);
|
||||
}
|
||||
|
||||
function barTable(el) {
|
||||
var bar = el && el.closest ? el.closest('.pw-filter') : null;
|
||||
return bar && bar.__pwTable ? bar.__pwTable : null;
|
||||
}
|
||||
|
||||
function eventTarget(ev) {
|
||||
var t = ev.target;
|
||||
if (t && t.nodeType !== 1)
|
||||
t = t.parentNode;
|
||||
return t;
|
||||
}
|
||||
|
||||
function bind(root) {
|
||||
root.addEventListener('click', function (ev) {
|
||||
var t = eventTarget(ev);
|
||||
if (t && t.getAttribute && t.getAttribute('data-pw-reset')) {
|
||||
var resetTable = barTable(t);
|
||||
if (!resetTable)
|
||||
return;
|
||||
ev.preventDefault();
|
||||
resetTable.__pwF = { sel: {}, q: '' };
|
||||
resetTable.__pwSig = null;
|
||||
refreshFilter(resetTable);
|
||||
return;
|
||||
}
|
||||
var el = t && t.closest ? t.closest('[data-pw-sort]') : null;
|
||||
if (!el || !root.contains(el))
|
||||
return;
|
||||
if (t.closest && t.closest('input, a, button, select'))
|
||||
return;
|
||||
var th = el.closest('th');
|
||||
var table = el.closest('table');
|
||||
if (!th || !table || !infoOf(table))
|
||||
return;
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
requestSort(table, th, el === th ? null : el, el.getAttribute('data-pw-sort'));
|
||||
});
|
||||
root.addEventListener('change', function (ev) {
|
||||
var t = eventTarget(ev);
|
||||
if (!t || !t.getAttribute || !t.getAttribute('data-pw-filter'))
|
||||
return;
|
||||
var table = barTable(t);
|
||||
if (!table)
|
||||
return;
|
||||
(table.__pwF = table.__pwF || { sel: {}, q: '' }).sel[t.getAttribute('data-pw-filter')] = t.value;
|
||||
refreshFilter(table);
|
||||
});
|
||||
root.addEventListener('input', function (ev) {
|
||||
var t = eventTarget(ev);
|
||||
if (!t || !t.getAttribute || !t.getAttribute('data-pw-search'))
|
||||
return;
|
||||
var table = barTable(t);
|
||||
if (!table)
|
||||
return;
|
||||
clearTimeout(searchTimer);
|
||||
searchTimer = setTimeout(function () {
|
||||
(table.__pwF = table.__pwF || { sel: {}, q: '' }).q = t.value;
|
||||
refreshFilter(table);
|
||||
}, 150);
|
||||
});
|
||||
root.addEventListener('keydown', function (ev) {
|
||||
var t = eventTarget(ev);
|
||||
if (ev.key === 'Enter' && t && t.getAttribute && t.getAttribute('data-pw-search'))
|
||||
ev.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
var box = document.getElementById('pw2-nodesort-i18n');
|
||||
var root = document.getElementById('node_list');
|
||||
if (!box || !root)
|
||||
return;
|
||||
state.app = box.getAttribute('data-app') || 'passwall2';
|
||||
state.text = readText(box);
|
||||
state.root = root;
|
||||
prepareCollator();
|
||||
if (!state.bound) {
|
||||
bind(root);
|
||||
state.bound = true;
|
||||
}
|
||||
}
|
||||
|
||||
function enhanceAll() {
|
||||
if (!state.root)
|
||||
return;
|
||||
var tables = state.root.querySelectorAll('table.cbi-section-table');
|
||||
for (var i = 0; i < tables.length; i++) {
|
||||
try {
|
||||
enhance(tables[i]);
|
||||
refreshFilter(tables[i]);
|
||||
} catch (e) {
|
||||
if (window.console)
|
||||
console.warn('passwall2 node list sort:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.pw2NodeSort = {
|
||||
init: init,
|
||||
enhanceAll: enhanceAll,
|
||||
rowVisible: rowVisible
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
var QRCode;!function(){function t(t){this.mode=r.MODE_8BIT_BYTE,this.data=t,this.parsedData=[];for(var e=0,o=this.data.length;e<o;e++){var i=[],n=this.data.charCodeAt(e);n>65536?(i[0]=240|(1835008&n)>>>18,i[1]=128|(258048&n)>>>12,i[2]=128|(4032&n)>>>6,i[3]=128|63&n):n>2048?(i[0]=224|(61440&n)>>>12,i[1]=128|(4032&n)>>>6,i[2]=128|63&n):n>128?(i[0]=192|(1984&n)>>>6,i[1]=128|63&n):i[0]=n,this.parsedData.push(i)}this.parsedData=Array.prototype.concat.apply([],this.parsedData),this.parsedData.length!=this.data.length&&(this.parsedData.unshift(191),this.parsedData.unshift(187),this.parsedData.unshift(239))}function e(t,e){this.typeNumber=t,this.errorCorrectLevel=e,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]}t.prototype={getLength:function(t){return this.parsedData.length},write:function(t){for(var e=0,r=this.parsedData.length;e<r;e++)t.put(this.parsedData[e],8)}},e.prototype={addData:function(e){var r=new t(e);this.dataList.push(r),this.dataCache=null},isDark:function(t,e){if(t<0||this.moduleCount<=t||e<0||this.moduleCount<=e)throw new Error(t+","+e);return this.modules[t][e]},getModuleCount:function(){return this.moduleCount},make:function(){this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(t,r){this.moduleCount=4*this.typeNumber+17,this.modules=new Array(this.moduleCount);for(var o=0;o<this.moduleCount;o++){this.modules[o]=new Array(this.moduleCount);for(var i=0;i<this.moduleCount;i++)this.modules[o][i]=null}this.setupPositionProbePattern(0,0),this.setupPositionProbePattern(this.moduleCount-7,0),this.setupPositionProbePattern(0,this.moduleCount-7),this.setupPositionAdjustPattern(),this.setupTimingPattern(),this.setupTypeInfo(t,r),this.typeNumber>=7&&this.setupTypeNumber(t),null==this.dataCache&&(this.dataCache=e.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,r)},setupPositionProbePattern:function(t,e){for(var r=-1;r<=7;r++)if(!(t+r<=-1||this.moduleCount<=t+r))for(var o=-1;o<=7;o++)e+o<=-1||this.moduleCount<=e+o||(this.modules[t+r][e+o]=0<=r&&r<=6&&(0==o||6==o)||0<=o&&o<=6&&(0==r||6==r)||2<=r&&r<=4&&2<=o&&o<=4)},getBestMaskPattern:function(){for(var t=0,e=0,r=0;r<8;r++){this.makeImpl(!0,r);var o=g.getLostPoint(this);(0==r||t>o)&&(t=o,e=r)}return e},createMovieClip:function(t,e,r){var o=t.createEmptyMovieClip(e,r);this.make();for(var i=0;i<this.modules.length;i++)for(var n=1*i,a=0;a<this.modules[i].length;a++){var s=1*a;this.modules[i][a]&&(o.beginFill(0,100),o.moveTo(s,n),o.lineTo(s+1,n),o.lineTo(s+1,n+1),o.lineTo(s,n+1),o.endFill())}return o},setupTimingPattern:function(){for(var t=8;t<this.moduleCount-8;t++)null==this.modules[t][6]&&(this.modules[t][6]=t%2==0);for(var e=8;e<this.moduleCount-8;e++)null==this.modules[6][e]&&(this.modules[6][e]=e%2==0)},setupPositionAdjustPattern:function(){for(var t=g.getPatternPosition(this.typeNumber),e=0;e<t.length;e++)for(var r=0;r<t.length;r++){var o=t[e],i=t[r];if(null==this.modules[o][i])for(var n=-2;n<=2;n++)for(var a=-2;a<=2;a++)this.modules[o+n][i+a]=-2==n||2==n||-2==a||2==a||0==n&&0==a}},setupTypeNumber:function(t){for(var e=g.getBCHTypeNumber(this.typeNumber),r=0;r<18;r++){var o=!t&&1==(e>>r&1);this.modules[Math.floor(r/3)][r%3+this.moduleCount-8-3]=o}for(r=0;r<18;r++){o=!t&&1==(e>>r&1);this.modules[r%3+this.moduleCount-8-3][Math.floor(r/3)]=o}},setupTypeInfo:function(t,e){for(var r=this.errorCorrectLevel<<3|e,o=g.getBCHTypeInfo(r),i=0;i<15;i++){var n=!t&&1==(o>>i&1);i<6?this.modules[i][8]=n:i<8?this.modules[i+1][8]=n:this.modules[this.moduleCount-15+i][8]=n}for(i=0;i<15;i++){n=!t&&1==(o>>i&1);i<8?this.modules[8][this.moduleCount-i-1]=n:i<9?this.modules[8][15-i-1+1]=n:this.modules[8][15-i-1]=n}this.modules[this.moduleCount-8][8]=!t},mapData:function(t,e){for(var r=-1,o=this.moduleCount-1,i=7,n=0,a=this.moduleCount-1;a>0;a-=2)for(6==a&&a--;;){for(var s=0;s<2;s++)if(null==this.modules[o][a-s]){var h=!1;n<t.length&&(h=1==(t[n]>>>i&1)),g.getMask(e,o,a-s)&&(h=!h),this.modules[o][a-s]=h,-1==--i&&(n++,i=7)}if((o+=r)<0||this.moduleCount<=o){o-=r,r=-r;break}}}},e.PAD0=236,e.PAD1=17,e.createData=function(t,r,o){for(var i=m.getRSBlocks(t,r),n=new _,a=0;a<o.length;a++){var s=o[a];n.put(s.mode,4),n.put(s.getLength(),g.getLengthInBits(s.mode,t)),s.write(n)}var h=0;for(a=0;a<i.length;a++)h+=i[a].dataCount;if(n.getLengthInBits()>8*h)throw new Error("code length overflow. ("+n.getLengthInBits()+">"+8*h+")");for(n.getLengthInBits()+4<=8*h&&n.put(0,4);n.getLengthInBits()%8!=0;)n.putBit(!1);for(;!(n.getLengthInBits()>=8*h||(n.put(e.PAD0,8),n.getLengthInBits()>=8*h));)n.put(e.PAD1,8);return e.createBytes(n,i)},e.createBytes=function(t,e){for(var r=0,o=0,i=0,n=new Array(e.length),a=new Array(e.length),s=0;s<e.length;s++){var h=e[s].dataCount,l=e[s].totalCount-h;o=Math.max(o,h),i=Math.max(i,l),n[s]=new Array(h);for(var u=0;u<n[s].length;u++)n[s][u]=255&t.buffer[u+r];r+=h;var f=g.getErrorCorrectPolynomial(l),d=new p(n[s],f.getLength()-1).mod(f);a[s]=new Array(f.getLength()-1);for(u=0;u<a[s].length;u++)Line truncated
|
||||
Reference in new issue
Block a user