// ==UserScript== // @name kk-copy-helper // @namespace https://greasyfork.org/zh-CN/users/1167332-stephenykk // @homepage https://greasyfork.org/zh-CN/scripts/514711-kk-copy-helper // @sourcecode https://gitee.com/stephenykk/tampermonkey-copy-helper.git // @version 1.0.31 // @description 文章拷贝助手,掘金、简书、微信文章、知乎专栏、思否、CSDN、新华网、人民网、 文章一键拷贝 markdown,欢迎关注 前端公众号:JS酷 // @author #前端公众号:JS酷 // @match https://juejin.cn/post/* // @match https://blog.csdn.net/*/article/details/* // @match https://www.jianshu.com/p/* // @match https://www.cnblogs.com/*/p/*.html // @match https://segmentfault.com/a/* // @match https://mp.weixin.qq.com/s* // @match https://zhuanlan.zhihu.com/p/* // @match https://sspai.com/post/* // @match https://panzhenjie.fun/* // @match http://localhost:4000/* // @match *://www.news.cn/*/**/*.htm* // @match *://*.people.com.cn/*/**/*.htm* // @icon https://res.wx.qq.com/a/fed_upload/9300e7ac-cec5-4454-b75c-f92260dd5b47/logo-mp.ico // @grant none // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/514711/kk-copy-helper.user.js // @updateURL https://update.greasyfork.icu/scripts/514711/kk-copy-helper.meta.js // ==/UserScript== /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ 5794: /***/ ((module) => { module.exports = { trueFunc: function trueFunc(){ return true; }, falseFunc: function falseFunc(){ return false; } }; /***/ }), /***/ 4993: /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.groupSelectors = exports.getDocumentRoot = void 0; var positionals_1 = __webpack_require__(6759); function getDocumentRoot(node) { while (node.parent) node = node.parent; return node; } exports.getDocumentRoot = getDocumentRoot; function groupSelectors(selectors) { var filteredSelectors = []; var plainSelectors = []; for (var _i = 0, selectors_1 = selectors; _i < selectors_1.length; _i++) { var selector = selectors_1[_i]; if (selector.some(positionals_1.isFilter)) { filteredSelectors.push(selector); } else { plainSelectors.push(selector); } } return [plainSelectors, filteredSelectors]; } exports.groupSelectors = groupSelectors; /***/ }), /***/ 3236: /***/ (function(__unused_webpack_module, exports, __webpack_require__) { "use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.select = exports.filter = exports.some = exports.is = exports.aliases = exports.pseudos = exports.filters = void 0; var css_what_1 = __webpack_require__(1923); var css_select_1 = __webpack_require__(9944); var DomUtils = __importStar(__webpack_require__(8839)); var helpers_1 = __webpack_require__(4993); var positionals_1 = __webpack_require__(6759); // Re-export pseudo extension points var css_select_2 = __webpack_require__(9944); Object.defineProperty(exports, "filters", ({ enumerable: true, get: function () { return css_select_2.filters; } })); Object.defineProperty(exports, "pseudos", ({ enumerable: true, get: function () { return css_select_2.pseudos; } })); Object.defineProperty(exports, "aliases", ({ enumerable: true, get: function () { return css_select_2.aliases; } })); /** Used to indicate a scope should be filtered. Might be ignored when filtering. */ var SCOPE_PSEUDO = { type: css_what_1.SelectorType.Pseudo, name: "scope", data: null, }; /** Used for actually filtering for scope. */ var CUSTOM_SCOPE_PSEUDO = __assign({}, SCOPE_PSEUDO); var UNIVERSAL_SELECTOR = { type: css_what_1.SelectorType.Universal, namespace: null, }; function is(element, selector, options) { if (options === void 0) { options = {}; } return some([element], selector, options); } exports.is = is; function some(elements, selector, options) { if (options === void 0) { options = {}; } if (typeof selector === "function") return elements.some(selector); var _a = (0, helpers_1.groupSelectors)((0, css_what_1.parse)(selector)), plain = _a[0], filtered = _a[1]; return ((plain.length > 0 && elements.some((0, css_select_1._compileToken)(plain, options))) || filtered.some(function (sel) { return filterBySelector(sel, elements, options).length > 0; })); } exports.some = some; function filterByPosition(filter, elems, data, options) { var num = typeof data === "string" ? parseInt(data, 10) : NaN; switch (filter) { case "first": case "lt": // Already done in `getLimit` return elems; case "last": return elems.length > 0 ? [elems[elems.length - 1]] : elems; case "nth": case "eq": return isFinite(num) && Math.abs(num) < elems.length ? [num < 0 ? elems[elems.length + num] : elems[num]] : []; case "gt": return isFinite(num) ? elems.slice(num + 1) : []; case "even": return elems.filter(function (_, i) { return i % 2 === 0; }); case "odd": return elems.filter(function (_, i) { return i % 2 === 1; }); case "not": { var filtered_1 = new Set(filterParsed(data, elems, options)); return elems.filter(function (e) { return !filtered_1.has(e); }); } } } function filter(selector, elements, options) { if (options === void 0) { options = {}; } return filterParsed((0, css_what_1.parse)(selector), elements, options); } exports.filter = filter; /** * Filter a set of elements by a selector. * * Will return elements in the original order. * * @param selector Selector to filter by. * @param elements Elements to filter. * @param options Options for selector. */ function filterParsed(selector, elements, options) { if (elements.length === 0) return []; var _a = (0, helpers_1.groupSelectors)(selector), plainSelectors = _a[0], filteredSelectors = _a[1]; var found; if (plainSelectors.length) { var filtered = filterElements(elements, plainSelectors, options); // If there are no filters, just return if (filteredSelectors.length === 0) { return filtered; } // Otherwise, we have to do some filtering if (filtered.length) { found = new Set(filtered); } } for (var i = 0; i < filteredSelectors.length && (found === null || found === void 0 ? void 0 : found.size) !== elements.length; i++) { var filteredSelector = filteredSelectors[i]; var missing = found ? elements.filter(function (e) { return DomUtils.isTag(e) && !found.has(e); }) : elements; if (missing.length === 0) break; var filtered = filterBySelector(filteredSelector, elements, options); if (filtered.length) { if (!found) { /* * If we haven't found anything before the last selector, * just return what we found now. */ if (i === filteredSelectors.length - 1) { return filtered; } found = new Set(filtered); } else { filtered.forEach(function (el) { return found.add(el); }); } } } return typeof found !== "undefined" ? (found.size === elements.length ? elements : // Filter elements to preserve order elements.filter(function (el) { return found.has(el); })) : []; } function filterBySelector(selector, elements, options) { var _a; if (selector.some(css_what_1.isTraversal)) { /* * Get root node, run selector with the scope * set to all of our nodes. */ var root = (_a = options.root) !== null && _a !== void 0 ? _a : (0, helpers_1.getDocumentRoot)(elements[0]); var sel = __spreadArray(__spreadArray([], selector, true), [CUSTOM_SCOPE_PSEUDO], false); return findFilterElements(root, sel, options, true, elements); } // Performance optimization: If we don't have to traverse, just filter set. return findFilterElements(elements, selector, options, false); } function select(selector, root, options) { if (options === void 0) { options = {}; } if (typeof selector === "function") { return find(root, selector); } var _a = (0, helpers_1.groupSelectors)((0, css_what_1.parse)(selector)), plain = _a[0], filtered = _a[1]; var results = filtered.map(function (sel) { return findFilterElements(root, sel, options, true); }); // Plain selectors can be queried in a single go if (plain.length) { results.push(findElements(root, plain, options, Infinity)); } if (results.length === 0) { return []; } // If there was only a single selector, just return the result if (results.length === 1) { return results[0]; } // Sort results, filtering for duplicates return DomUtils.uniqueSort(results.reduce(function (a, b) { return __spreadArray(__spreadArray([], a, true), b, true); })); } exports.select = select; // Traversals that are treated differently in css-select. var specialTraversal = new Set([ css_what_1.SelectorType.Descendant, css_what_1.SelectorType.Adjacent, ]); function includesScopePseudo(t) { return (t !== SCOPE_PSEUDO && t.type === "pseudo" && (t.name === "scope" || (Array.isArray(t.data) && t.data.some(function (data) { return data.some(includesScopePseudo); })))); } function addContextIfScope(selector, options, scopeContext) { return scopeContext && selector.some(includesScopePseudo) ? __assign(__assign({}, options), { context: scopeContext }) : options; } /** * * @param root Element(s) to search from. * @param selector Selector to look for. * @param options Options for querying. * @param queryForSelector Query multiple levels deep for the initial selector, even if it doesn't contain a traversal. * @param scopeContext Optional context for a :scope. */ function findFilterElements(root, selector, options, queryForSelector, scopeContext) { var filterIndex = selector.findIndex(positionals_1.isFilter); var sub = selector.slice(0, filterIndex); var filter = selector[filterIndex]; /* * Set the number of elements to retrieve. * Eg. for :first, we only have to get a single element. */ var limit = (0, positionals_1.getLimit)(filter.name, filter.data); if (limit === 0) return []; var subOpts = addContextIfScope(sub, options, scopeContext); /* * Skip `findElements` call if our selector starts with a positional * pseudo. */ var elemsNoLimit = sub.length === 0 && !Array.isArray(root) ? DomUtils.getChildren(root).filter(DomUtils.isTag) : sub.length === 0 || (sub.length === 1 && sub[0] === SCOPE_PSEUDO) ? (Array.isArray(root) ? root : [root]).filter(DomUtils.isTag) : queryForSelector || sub.some(css_what_1.isTraversal) ? findElements(root, [sub], subOpts, limit) : filterElements(root, [sub], subOpts); var elems = elemsNoLimit.slice(0, limit); var result = filterByPosition(filter.name, elems, filter.data, options); if (result.length === 0 || selector.length === filterIndex + 1) { return result; } var remainingSelector = selector.slice(filterIndex + 1); var remainingHasTraversal = remainingSelector.some(css_what_1.isTraversal); var remainingOpts = addContextIfScope(remainingSelector, options, scopeContext); if (remainingHasTraversal) { /* * Some types of traversals have special logic when they start a selector * in css-select. If this is the case, add a universal selector in front of * the selector to avoid this behavior. */ if (specialTraversal.has(remainingSelector[0].type)) { remainingSelector.unshift(UNIVERSAL_SELECTOR); } /* * Add a scope token in front of the remaining selector, * to make sure traversals don't match elements that aren't a * part of the considered tree. */ remainingSelector.unshift(SCOPE_PSEUDO); } /* * If we have another filter, recursively call `findFilterElements`, * with the `recursive` flag disabled. We only have to look for more * elements when we see a traversal. * * Otherwise, */ return remainingSelector.some(positionals_1.isFilter) ? findFilterElements(result, remainingSelector, options, false, scopeContext) : remainingHasTraversal ? // Query existing elements to resolve traversal. findElements(result, [remainingSelector], remainingOpts, Infinity) : // If we don't have any more traversals, simply filter elements. filterElements(result, [remainingSelector], remainingOpts); } function findElements(root, sel, options, limit) { if (limit === 0) return []; var query = (0, css_select_1._compileToken)(sel, options, root); return find(root, query, limit); } function find(root, query, limit) { if (limit === void 0) { limit = Infinity; } var elems = (0, css_select_1.prepareContext)(root, DomUtils, query.shouldTestNextSiblings); return DomUtils.find(function (node) { return DomUtils.isTag(node) && query(node); }, elems, true, limit); } function filterElements(elements, sel, options) { var els = (Array.isArray(elements) ? elements : [elements]).filter(DomUtils.isTag); if (els.length === 0) return els; var query = (0, css_select_1._compileToken)(sel, options); return els.filter(query); } /***/ }), /***/ 6759: /***/ ((__unused_webpack_module, exports) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.getLimit = exports.isFilter = exports.filterNames = void 0; exports.filterNames = new Set([ "first", "last", "eq", "gt", "nth", "lt", "even", "odd", ]); function isFilter(s) { if (s.type !== "pseudo") return false; if (exports.filterNames.has(s.name)) return true; if (s.name === "not" && Array.isArray(s.data)) { // Only consider `:not` with embedded filters return s.data.some(function (s) { return s.some(isFilter); }); } return false; } exports.isFilter = isFilter; function getLimit(filter, data) { var num = data != null ? parseInt(data, 10) : NaN; switch (filter) { case "first": return 1; case "nth": case "eq": return isFinite(num) ? (num >= 0 ? num + 1 : Infinity) : 0; case "lt": return isFinite(num) ? (num >= 0 ? num : Infinity) : 0; case "gt": return isFinite(num) ? Infinity : 0; default: return Infinity; } } exports.getLimit = getLimit; /***/ }), /***/ 6031: /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; /** * Methods for getting and modifying attributes. * * @module cheerio/attributes */ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.toggleClass = exports.removeClass = exports.addClass = exports.hasClass = exports.removeAttr = exports.val = exports.data = exports.prop = exports.attr = void 0; var static_1 = __webpack_require__(7645); var utils_1 = __webpack_require__(1098); var hasOwn = Object.prototype.hasOwnProperty; var rspace = /\s+/; var dataAttrPrefix = 'data-'; /* * Lookup table for coercing string data-* attributes to their corresponding * JavaScript primitives */ var primitives = { null: null, true: true, false: false, }; // Attributes that are booleans var rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i; // Matches strings that look like JSON objects or arrays var rbrace = /^{[^]*}$|^\[[^]*]$/; function getAttr(elem, name, xmlMode) { var _a; if (!elem || !utils_1.isTag(elem)) return undefined; (_a = elem.attribs) !== null && _a !== void 0 ? _a : (elem.attribs = {}); // Return the entire attribs object if no attribute specified if (!name) { return elem.attribs; } if (hasOwn.call(elem.attribs, name)) { // Get the (decoded) attribute return !xmlMode && rboolean.test(name) ? name : elem.attribs[name]; } // Mimic the DOM and return text content as value for `option's` if (elem.name === 'option' && name === 'value') { return static_1.text(elem.children); } // Mimic DOM with default value for radios/checkboxes if (elem.name === 'input' && (elem.attribs.type === 'radio' || elem.attribs.type === 'checkbox') && name === 'value') { return 'on'; } return undefined; } /** * Sets the value of an attribute. The attribute will be deleted if the value is `null`. * * @private * @param el - The element to set the attribute on. * @param name - The attribute's name. * @param value - The attribute's value. */ function setAttr(el, name, value) { if (value === null) { removeAttribute(el, name); } else { el.attribs[name] = "" + value; } } function attr(name, value) { // Set the value (with attr map support) if (typeof name === 'object' || value !== undefined) { if (typeof value === 'function') { if (typeof name !== 'string') { { throw new Error('Bad combination of arguments.'); } } return utils_1.domEach(this, function (el, i) { if (utils_1.isTag(el)) setAttr(el, name, value.call(el, i, el.attribs[name])); }); } return utils_1.domEach(this, function (el) { if (!utils_1.isTag(el)) return; if (typeof name === 'object') { Object.keys(name).forEach(function (objName) { var objValue = name[objName]; setAttr(el, objName, objValue); }); } else { setAttr(el, name, value); } }); } return arguments.length > 1 ? this : getAttr(this[0], name, this.options.xmlMode); } exports.attr = attr; /** * Gets a node's prop. * * @private * @category Attributes * @param el - Elenent to get the prop of. * @param name - Name of the prop. * @returns The prop's value. */ function getProp(el, name, xmlMode) { if (!el || !utils_1.isTag(el)) return; return name in el ? // @ts-expect-error TS doesn't like us accessing the value directly here. el[name] : !xmlMode && rboolean.test(name) ? getAttr(el, name, false) !== undefined : getAttr(el, name, xmlMode); } /** * Sets the value of a prop. * * @private * @param el - The element to set the prop on. * @param name - The prop's name. * @param value - The prop's value. */ function setProp(el, name, value, xmlMode) { if (name in el) { // @ts-expect-error Overriding value el[name] = value; } else { setAttr(el, name, !xmlMode && rboolean.test(name) ? (value ? '' : null) : "" + value); } } function prop(name, value) { var _this = this; if (typeof name === 'string' && value === undefined) { switch (name) { case 'style': { var property_1 = this.css(); var keys = Object.keys(property_1); keys.forEach(function (p, i) { property_1[i] = p; }); property_1.length = keys.length; return property_1; } case 'tagName': case 'nodeName': { var el = this[0]; return utils_1.isTag(el) ? el.name.toUpperCase() : undefined; } case 'outerHTML': return this.clone().wrap('').parent().html(); case 'innerHTML': return this.html(); default: return getProp(this[0], name, this.options.xmlMode); } } if (typeof name === 'object' || value !== undefined) { if (typeof value === 'function') { if (typeof name === 'object') { throw new Error('Bad combination of arguments.'); } return utils_1.domEach(this, function (el, i) { if (utils_1.isTag(el)) setProp(el, name, value.call(el, i, getProp(el, name, _this.options.xmlMode)), _this.options.xmlMode); }); } return utils_1.domEach(this, function (el) { if (!utils_1.isTag(el)) return; if (typeof name === 'object') { Object.keys(name).forEach(function (key) { var val = name[key]; setProp(el, key, val, _this.options.xmlMode); }); } else { setProp(el, name, value, _this.options.xmlMode); } }); } return undefined; } exports.prop = prop; /** * Sets the value of a data attribute. * * @private * @param el - The element to set the data attribute on. * @param name - The data attribute's name. * @param value - The data attribute's value. */ function setData(el, name, value) { var _a; var elem = el; (_a = elem.data) !== null && _a !== void 0 ? _a : (elem.data = {}); if (typeof name === 'object') Object.assign(elem.data, name); else if (typeof name === 'string' && value !== undefined) { elem.data[name] = value; } } /** * Read the specified attribute from the equivalent HTML5 `data-*` attribute, * and (if present) cache the value in the node's internal data store. If no * attribute name is specified, read *all* HTML5 `data-*` attributes in this manner. * * @private * @category Attributes * @param el - Elenent to get the data attribute of. * @param name - Name of the data attribute. * @returns The data attribute's value, or a map with all of the data attribute. */ function readData(el, name) { var domNames; var jsNames; var value; if (name == null) { domNames = Object.keys(el.attribs).filter(function (attrName) { return attrName.startsWith(dataAttrPrefix); }); jsNames = domNames.map(function (domName) { return utils_1.camelCase(domName.slice(dataAttrPrefix.length)); }); } else { domNames = [dataAttrPrefix + utils_1.cssCase(name)]; jsNames = [name]; } for (var idx = 0; idx < domNames.length; ++idx) { var domName = domNames[idx]; var jsName = jsNames[idx]; if (hasOwn.call(el.attribs, domName) && !hasOwn.call(el.data, jsName)) { value = el.attribs[domName]; if (hasOwn.call(primitives, value)) { value = primitives[value]; } else if (value === String(Number(value))) { value = Number(value); } else if (rbrace.test(value)) { try { value = JSON.parse(value); } catch (e) { /* Ignore */ } } el.data[jsName] = value; } } return name == null ? el.data : value; } function data(name, value) { var _a; var elem = this[0]; if (!elem || !utils_1.isTag(elem)) return; var dataEl = elem; (_a = dataEl.data) !== null && _a !== void 0 ? _a : (dataEl.data = {}); // Return the entire data object if no data specified if (!name) { return readData(dataEl); } // Set the value (with attr map support) if (typeof name === 'object' || value !== undefined) { utils_1.domEach(this, function (el) { if (utils_1.isTag(el)) if (typeof name === 'object') setData(el, name); else setData(el, name, value); }); return this; } if (hasOwn.call(dataEl.data, name)) { return dataEl.data[name]; } return readData(dataEl, name); } exports.data = data; function val(value) { var querying = arguments.length === 0; var element = this[0]; if (!element || !utils_1.isTag(element)) return querying ? undefined : this; switch (element.name) { case 'textarea': return this.text(value); case 'select': { var option = this.find('option:selected'); if (!querying) { if (this.attr('multiple') == null && typeof value === 'object') { return this; } this.find('option').removeAttr('selected'); var values = typeof value !== 'object' ? [value] : value; for (var i = 0; i < values.length; i++) { this.find("option[value=\"" + values[i] + "\"]").attr('selected', ''); } return this; } return this.attr('multiple') ? option.toArray().map(function (el) { return static_1.text(el.children); }) : option.attr('value'); } case 'input': case 'option': return querying ? this.attr('value') : this.attr('value', value); } return undefined; } exports.val = val; /** * Remove an attribute. * * @private * @param elem - Node to remove attribute from. * @param name - Name of the attribute to remove. */ function removeAttribute(elem, name) { if (!elem.attribs || !hasOwn.call(elem.attribs, name)) return; delete elem.attribs[name]; } /** * Splits a space-separated list of names to individual names. * * @category Attributes * @param names - Names to split. * @returns - Split names. */ function splitNames(names) { return names ? names.trim().split(rspace) : []; } /** * Method for removing attributes by `name`. * * @category Attributes * @example * * ```js * $('.pear').removeAttr('class').html(); * //=>
  • Pear
  • * * $('.apple').attr('id', 'favorite'); * $('.apple').removeAttr('id class').html(); * //=>
  • Apple
  • * ``` * * @param name - Name of the attribute. * @returns The instance itself. * @see {@link https://api.jquery.com/removeAttr/} */ function removeAttr(name) { var attrNames = splitNames(name); var _loop_1 = function (i) { utils_1.domEach(this_1, function (elem) { if (utils_1.isTag(elem)) removeAttribute(elem, attrNames[i]); }); }; var this_1 = this; for (var i = 0; i < attrNames.length; i++) { _loop_1(i); } return this; } exports.removeAttr = removeAttr; /** * Check to see if *any* of the matched elements have the given `className`. * * @category Attributes * @example * * ```js * $('.pear').hasClass('pear'); * //=> true * * $('apple').hasClass('fruit'); * //=> false * * $('li').hasClass('pear'); * //=> true * ``` * * @param className - Name of the class. * @returns Indicates if an element has the given `className`. * @see {@link https://api.jquery.com/hasClass/} */ function hasClass(className) { return this.toArray().some(function (elem) { var clazz = utils_1.isTag(elem) && elem.attribs.class; var idx = -1; if (clazz && className.length) { while ((idx = clazz.indexOf(className, idx + 1)) > -1) { var end = idx + className.length; if ((idx === 0 || rspace.test(clazz[idx - 1])) && (end === clazz.length || rspace.test(clazz[end]))) { return true; } } } return false; }); } exports.hasClass = hasClass; /** * Adds class(es) to all of the matched elements. Also accepts a `function`. * * @category Attributes * @example * * ```js * $('.pear').addClass('fruit').html(); * //=>
  • Pear
  • * * $('.apple').addClass('fruit red').html(); * //=>
  • Apple
  • * ``` * * @param value - Name of new class. * @returns The instance itself. * @see {@link https://api.jquery.com/addClass/} */ function addClass(value) { // Support functions if (typeof value === 'function') { return utils_1.domEach(this, function (el, i) { if (utils_1.isTag(el)) { var className = el.attribs.class || ''; addClass.call([el], value.call(el, i, className)); } }); } // Return if no value or not a string or function if (!value || typeof value !== 'string') return this; var classNames = value.split(rspace); var numElements = this.length; for (var i = 0; i < numElements; i++) { var el = this[i]; // If selected element isn't a tag, move on if (!utils_1.isTag(el)) continue; // If we don't already have classes — always set xmlMode to false here, as it doesn't matter for classes var className = getAttr(el, 'class', false); if (!className) { setAttr(el, 'class', classNames.join(' ').trim()); } else { var setClass = " " + className + " "; // Check if class already exists for (var j = 0; j < classNames.length; j++) { var appendClass = classNames[j] + " "; if (!setClass.includes(" " + appendClass)) setClass += appendClass; } setAttr(el, 'class', setClass.trim()); } } return this; } exports.addClass = addClass; /** * Removes one or more space-separated classes from the selected elements. If no * `className` is defined, all classes will be removed. Also accepts a `function`. * * @category Attributes * @example * * ```js * $('.pear').removeClass('pear').html(); * //=>
  • Pear
  • * * $('.apple').addClass('red').removeClass().html(); * //=>
  • Apple
  • * ``` * * @param name - Name of the class. If not specified, removes all elements. * @returns The instance itself. * @see {@link https://api.jquery.com/removeClass/} */ function removeClass(name) { // Handle if value is a function if (typeof name === 'function') { return utils_1.domEach(this, function (el, i) { if (utils_1.isTag(el)) removeClass.call([el], name.call(el, i, el.attribs.class || '')); }); } var classes = splitNames(name); var numClasses = classes.length; var removeAll = arguments.length === 0; return utils_1.domEach(this, function (el) { if (!utils_1.isTag(el)) return; if (removeAll) { // Short circuit the remove all case as this is the nice one el.attribs.class = ''; } else { var elClasses = splitNames(el.attribs.class); var changed = false; for (var j = 0; j < numClasses; j++) { var index = elClasses.indexOf(classes[j]); if (index >= 0) { elClasses.splice(index, 1); changed = true; /* * We have to do another pass to ensure that there are not duplicate * classes listed */ j--; } } if (changed) { el.attribs.class = elClasses.join(' '); } } }); } exports.removeClass = removeClass; /** * Add or remove class(es) from the matched elements, depending on either the * class's presence or the value of the switch argument. Also accepts a `function`. * * @category Attributes * @example * * ```js * $('.apple.green').toggleClass('fruit green red').html(); * //=>
  • Apple
  • * * $('.apple.green').toggleClass('fruit green red', true).html(); * //=>
  • Apple
  • * ``` * * @param value - Name of the class. Can also be a function. * @param stateVal - If specified the state of the class. * @returns The instance itself. * @see {@link https://api.jquery.com/toggleClass/} */ function toggleClass(value, stateVal) { // Support functions if (typeof value === 'function') { return utils_1.domEach(this, function (el, i) { if (utils_1.isTag(el)) { toggleClass.call([el], value.call(el, i, el.attribs.class || '', stateVal), stateVal); } }); } // Return if no value or not a string or function if (!value || typeof value !== 'string') return this; var classNames = value.split(rspace); var numClasses = classNames.length; var state = typeof stateVal === 'boolean' ? (stateVal ? 1 : -1) : 0; var numElements = this.length; for (var i = 0; i < numElements; i++) { var el = this[i]; // If selected element isn't a tag, move on if (!utils_1.isTag(el)) continue; var elementClasses = splitNames(el.attribs.class); // Check if class already exists for (var j = 0; j < numClasses; j++) { // Check if the class name is currently defined var index = elementClasses.indexOf(classNames[j]); // Add if stateValue === true or we are toggling and there is no value if (state >= 0 && index < 0) { elementClasses.push(classNames[j]); } else if (state <= 0 && index >= 0) { // Otherwise remove but only if the item exists elementClasses.splice(index, 1); } } el.attribs.class = elementClasses.join(' '); } return this; } exports.toggleClass = toggleClass; /***/ }), /***/ 723: /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.css = void 0; var utils_1 = __webpack_require__(1098); function css(prop, val) { if ((prop != null && val != null) || // When `prop` is a "plain" object (typeof prop === 'object' && !Array.isArray(prop))) { return utils_1.domEach(this, function (el, i) { if (utils_1.isTag(el)) { // `prop` can't be an array here anymore. setCss(el, prop, val, i); } }); } return getCss(this[0], prop); } exports.css = css; /** * Set styles of all elements. * * @private * @param el - Element to set style of. * @param prop - Name of property. * @param value - Value to set property to. * @param idx - Optional index within the selection. */ function setCss(el, prop, value, idx) { if (typeof prop === 'string') { var styles = getCss(el); var val = typeof value === 'function' ? value.call(el, idx, styles[prop]) : value; if (val === '') { delete styles[prop]; } else if (val != null) { styles[prop] = val; } el.attribs.style = stringify(styles); } else if (typeof prop === 'object') { Object.keys(prop).forEach(function (k, i) { setCss(el, k, prop[k], i); }); } } function getCss(el, prop) { if (!el || !utils_1.isTag(el)) return; var styles = parse(el.attribs.style); if (typeof prop === 'string') { return styles[prop]; } if (Array.isArray(prop)) { var newStyles_1 = {}; prop.forEach(function (item) { if (styles[item] != null) { newStyles_1[item] = styles[item]; } }); return newStyles_1; } return styles; } /** * Stringify `obj` to styles. * * @private * @category CSS * @param obj - Object to stringify. * @returns The serialized styles. */ function stringify(obj) { return Object.keys(obj).reduce(function (str, prop) { return "" + str + (str ? ' ' : '') + prop + ": " + obj[prop] + ";"; }, ''); } /** * Parse `styles`. * * @private * @category CSS * @param styles - Styles to be parsed. * @returns The parsed styles. */ function parse(styles) { styles = (styles || '').trim(); if (!styles) return {}; return styles.split(';').reduce(function (obj, str) { var n = str.indexOf(':'); // Skip if there is no :, or if it is the first/last character if (n < 1 || n === str.length - 1) return obj; obj[str.slice(0, n).trim()] = str.slice(n + 1).trim(); return obj; }, {}); } /***/ }), /***/ 295: /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.serializeArray = exports.serialize = void 0; var utils_1 = __webpack_require__(1098); /* * https://github.com/jquery/jquery/blob/2.1.3/src/manipulation/var/rcheckableType.js * https://github.com/jquery/jquery/blob/2.1.3/src/serialize.js */ var submittableSelector = 'input,select,textarea,keygen'; var r20 = /%20/g; var rCRLF = /\r?\n/g; /** * Encode a set of form elements as a string for submission. * * @category Forms * @returns The serialized form. * @see {@link https://api.jquery.com/serialize/} */ function serialize() { // Convert form elements into name/value objects var arr = this.serializeArray(); // Serialize each element into a key/value string var retArr = arr.map(function (data) { return encodeURIComponent(data.name) + "=" + encodeURIComponent(data.value); }); // Return the resulting serialization return retArr.join('&').replace(r20, '+'); } exports.serialize = serialize; /** * Encode a set of form elements as an array of names and values. * * @category Forms * @example * * ```js * $('
    ').serializeArray(); * //=> [ { name: 'foo', value: 'bar' } ] * ``` * * @returns The serialized form. * @see {@link https://api.jquery.com/serializeArray/} */ function serializeArray() { var _this = this; // Resolve all form elements from either forms or collections of form elements return this.map(function (_, elem) { var $elem = _this._make(elem); if (utils_1.isTag(elem) && elem.name === 'form') { return $elem.find(submittableSelector).toArray(); } return $elem.filter(submittableSelector).toArray(); }) .filter( // Verify elements have a name (`attr.name`) and are not disabled (`:enabled`) '[name!=""]:enabled' + // And cannot be clicked (`[type=submit]`) or are used in `x-www-form-urlencoded` (`[type=file]`) ':not(:submit, :button, :image, :reset, :file)' + // And are either checked/don't have a checkable state ':matches([checked], :not(:checkbox, :radio))' // Convert each of the elements to its value(s) ) .map(function (_, elem) { var _a; var $elem = _this._make(elem); var name = $elem.attr('name'); // We have filtered for elements with a name before. // If there is no value set (e.g. `undefined`, `null`), then default value to empty var value = (_a = $elem.val()) !== null && _a !== void 0 ? _a : ''; // If we have an array of values (e.g. `