Diff
checker
Texto
Texto
Imagens
Documentos
Excel
Pastas
Legal
Enterprise
Aplicativo para desktop
Preços
Fazer login
Baixar o Diffchecker Desktop
Comparar texto
Encontre a diferença entre dois arquivos de texto
Ferramentas
Histórico
Editor live
Ocultar espaços em branco
Recolher inalteradas
Sem quebra de linha
Layout
Dividido
Unificado
Nível de detalhe
Inteligente
Palavra
Caractere
Estilos de texto
Alterar aparência
Realce de sintaxe
Escolher sintaxe
Ignorar
Transformar texto
Ir à primeira mudança
Editar entrada
Diffchecker Desktop
A maneira mais segura de usar o Diffchecker. Obtenha o aplicativo Diffchecker Desktop: seus diffs nunca saem do seu computador!
Obter Desktop
Untitled diff
Criado
há 9 anos
O diff nunca expira
Limpar
Exportar
Compartilhar
Explicar
94 remoções
Linhas
Total
Removido
Caracteres
Total
Removido
Para continuar usando este recurso, atualize para
Diff
checker
Pro
Ver preços
209 linhas
Copiar tudo
57 adições
Linhas
Total
Adicionado
Caracteres
Total
Adicionado
Para continuar usando este recurso, atualize para
Diff
checker
Pro
Ver preços
174 linhas
Copiar tudo
'use strict';
'use strict';
exports.type = 'full';
exports.type = 'full';
exports.active = true;
exports.active = true;
exports.description = 'removes unused IDs and minifies used';
exports.description = 'removes unused IDs and minifies used';
exports.params = {
exports.params = {
remove: true,
remove: true,
minify: true,
minify: true,
Copiar
Copiado
Copiar
Copiado
prefix: ''
prefix: ''
,
preserve: [],
force: false
};
};
Copiar
Copiado
Copiar
Copiado
var referencesProps =
require('./_collections').referencesProps
,
var referencesProps =
new Set(
require('./_collections').referencesProps
)
,
regReferencesUrl = /\burl\(("|')?#(.+?)\1\)/,
regReferencesUrl = /\burl\(("|')?#(.+?)\1\)/,
regReferencesHref = /^#(.+?)$/,
regReferencesHref = /^#(.+?)$/,
regReferencesBegin = /^(\w+?)\./,
regReferencesBegin = /^(\w+?)\./,
styleOrScript = ['style', 'script'],
styleOrScript = ['style', 'script'],
generateIDchars = [
generateIDchars = [
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
],
],
maxIDindex = generateIDchars.length - 1;
maxIDindex = generateIDchars.length - 1;
/**
/**
* Remove unused and minify used IDs
* Remove unused and minify used IDs
* (only if there are no any <style> or <script>).
* (only if there are no any <style> or <script>).
*
*
* @param {Object} item current iteration item
* @param {Object} item current iteration item
* @param {Object} params plugin params
* @param {Object} params plugin params
*
*
* @author Kir Belevich
* @author Kir Belevich
*/
*/
exports.fn = function(data, params) {
exports.fn = function(data, params) {
Copiar
Copiado
Copiar
Copiado
var currentID,
var currentID,
currentIDstring,
currentIDstring,
Copiar
Copiado
Copiar
Copiado
IDs =
Object.create(null
),
IDs =
new Map(
),
referencesIDs =
Object.create(null
),
referencesIDs =
new Map(
),
idPrefix = 'id-', // prefix IDs so that values like '__proto__' don't break the work
hasStyleOrScript = false
,
hasStyleOrScript = false
;
preserveIDs = new Set(Array.isArray(params.preserve) ? params.preserve : params.preserve ? [params.preserve] : []),
idValuePrefix = '#',
idValuePostfix = '.';
/**
/**
* Bananas!
* Bananas!
*
*
* @param {Array} items input items
* @param {Array} items input items
* @return {Array} output items
* @return {Array} output items
*/
*/
function monkeys(items) {
function monkeys(items) {
Copiar
Copiado
Copiar
Copiado
for (var i = 0; i < items.content.length && !hasStyleOrScript; i++) {
for (var i = 0; i < items.content.length && !hasStyleOrScript; i++) {
Copiar
Copiado
Copiar
Copiado
var item = items.content[i]
;
var item = items.content[i]
,
match
;
Copiar
Copiado
Copiar
Copiado
//
check
if <style> of <script> presents
//
quit
if <style> of <script> presents
('force' param prevents quitting)
if (
item.isElem(styleOrScript)) {
if (
!params.force &&
item.isElem(styleOrScript)) {
hasStyleOrScript = true;
hasStyleOrScript = true;
continue;
continue;
}
}
Copiar
Copiado
Copiar
Copiado
// …and don't remove any ID if yes
// …and don't remove any ID if yes
if (item.isElem()) {
if (item.isElem()) {
Copiar
Copiado
Copiar
Copiado
item.eachAttr(function(attr) {
item.eachAttr(function(attr) {
Copiar
Copiado
Copiar
Copiado
var key
;
var key
, match;
// save IDs
// save IDs
if (attr.name === 'id') {
if (attr.name === 'id') {
Copiar
Copiado
Copiar
Copiado
key =
idPrefix +
attr.value;
key =
attr.value;
if (
key in
IDs
) {
if (
IDs
.has(key)
) {
item.removeAttr('id');
item.removeAttr('id');
// remove repeated id
} else {
} else {
Copiar
Copiado
Copiar
Copiado
IDs
[
key
] =
item
;
IDs
.set(
key
,
item
);
}
}
// save IDs url() references
else if (referencesProps.indexOf(attr.name) > -1) {
match = attr.value.match(regReferencesUrl);
if (match) {
key = idPrefix + match[2];
if (referencesIDs[key]) {
referencesIDs[key].push(attr);
} else {
referencesIDs[key] = [attr];
}
}
}
Copiar
Copiado
Copiar
Copiado
return;
}
}
Copiar
Copiado
Copiar
Copiado
// save
references
// save
IDs href
references
if (referencesProps.has(attr.name) && (match = attr.value.match(regReferencesUrl))) {
else if (
key = match[2]; // url() reference
}
else if (
attr.local === 'href' && (match = attr.value.match(regReferencesHref)) ||
attr.local === 'href' && (match = attr.value.match(regReferencesHref)) ||
attr.name === 'begin' && (match = attr.value.match(regReferencesBegin))
attr.name === 'begin' && (match = attr.value.match(regReferencesBegin))
) {
) {
Copiar
Copiado
Copiar
Copiado
key =
idPrefix +
match[1];
key =
match[1];
// href reference
if (
referencesIDs[
key
]
) {
}
referencesIDs
[
key
]
.push(attr);
if (
key
) {
} else {
var ref =
referencesIDs
.get(
key
) || [];
referencesIDs
[
key
] = [attr];
ref
.push(attr);
}
referencesIDs
.set(
key
, ref);
}
}
});
});
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
// go deeper
// go deeper
if (item.content) {
if (item.content) {
monkeys(item);
monkeys(item);
}
}
}
}
Copiar
Copiado
Copiar
Copiado
return items;
return items;
Copiar
Copiado
Copiar
Copiado
}
}
data = monkeys(data);
data = monkeys(data);
if (hasStyleOrScript) {
if (hasStyleOrScript) {
return data;
return data;
}
}
Copiar
Copiado
Copiar
Copiado
var idKey;
for (var
ref of
referencesIDs) {
for (var
k in
referencesIDs) {
var key
=
ref[0];
if (IDs[k]) {
idKey
=
k;
if (IDs.has(key)) {
k = k.replace(idPrefix, '');
// replace referenced IDs with the minified ones
// replace referenced IDs with the minified ones
Copiar
Copiado
Copiar
Copiado
if (params.minify
) {
if (params.minify
&& !preserveIDs.has(key)
) {
currentIDstring = getIDstring(currentID = generateID(currentID), params);
currentIDstring = getIDstring(currentID = generateID(currentID), params);
Copiar
Copiado
Copiar
Copiado
IDs
[idKey]
.attr('id').value = currentIDstring;
IDs
.get(key)
.attr('id').value = currentIDstring;
referencesIDs[idKey].forEach(function(attr) {
attr.value = attr.value
.replace('#' + k, '#' + currentIDstring)
.replace(k + '.', currentIDstring + '.');
});
Copiar
Copiado
Copiar
Copiado
idKey = idPrefix + k;
for (var attr of ref[1]) {
attr.value = attr.value.includes(idValuePrefix) ?
attr.value.replace(idValuePrefix + key, idValuePrefix + currentIDstring) :
attr.value.replace(key + idValuePostfix, currentIDstring + idValuePostfix);
}
}
}
Copiar
Copiado
Copiar
Copiado
// don't remove referenced IDs
// don't remove referenced IDs
Copiar
Copiado
Copiar
Copiado
delete
IDs[idKey]
;
IDs.
delete
(key)
;
}
}
}
}
Copiar
Copiado
Copiar
Copiado
// remove non-referenced IDs attributes from elements
// remove non-referenced IDs attributes from elements
if (params.remove) {
if (params.remove) {
Copiar
Copiado
Copiar
Copiado
for(var
keyElem of
IDs) {
for(var
ID in
IDs) {
if (!preserveIDs.has(keyElem[0])) {
IDs[ID
].removeAttr('id');
keyElem[1
].removeAttr('id');
}
}
}
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
return data;
return data;
Copiar
Copiado
Copiar
Copiado
};
};
/**
/**
* Generate unique minimal ID.
* Generate unique minimal ID.
*
*
* @param {Array} [currentID] current ID
* @param {Array} [currentID] current ID
* @return {Array} generated ID array
* @return {Array} generated ID array
*/
*/
function generateID(currentID) {
function generateID(currentID) {
Copiar
Copiado
Copiar
Copiado
if (!currentID) return [0];
if (!currentID) return [0];
currentID[currentID.length - 1]++;
currentID[currentID.length - 1]++;
for(var i = currentID.length - 1; i > 0; i--) {
for(var i = currentID.length - 1; i > 0; i--) {
if (currentID[i] > maxIDindex) {
if (currentID[i] > maxIDindex) {
currentID[i] = 0;
currentID[i] = 0;
if (currentID[i - 1] !== undefined) {
if (currentID[i - 1] !== undefined) {
currentID[i - 1]++;
currentID[i - 1]++;
}
}
}
}
}
}
Copiar
Copiado
Copiar
Copiado
if (currentID[0] > maxIDindex) {
if (currentID[0] > maxIDindex) {
currentID[0] = 0;
currentID[0] = 0;
currentID.unshift(0);
currentID.unshift(0);
}
}
Copiar
Copiado
Copiar
Copiado
return currentID;
return currentID;
Copiar
Copiado
Copiar
Copiado
}
}
/**
/**
* Get string from generated ID array.
* Get string from generated ID array.
*
*
* @param {Array} arr input ID array
* @param {Array} arr input ID array
* @return {String} output ID string
* @return {String} output ID string
*/
*/
function getIDstring(arr, params) {
function getIDstring(arr, params) {
Copiar
Copiado
Copiar
Copiado
var str = params.prefix;
var str = params.prefix;
Copiar
Copiado
Copiar
Copiado
return
str +
arr.map(i =>
generateIDchars[i]
).join('');
arr.forEach(function(i) {
str +
=
generateIDchars[i]
;
});
return str;
}
}
Diferenças salvas
Texto original
Abrir arquivo
'use strict'; exports.type = 'full'; exports.active = true; exports.description = 'removes unused IDs and minifies used'; exports.params = { remove: true, minify: true, prefix: '' }; var referencesProps = require('./_collections').referencesProps, regReferencesUrl = /\burl\(("|')?#(.+?)\1\)/, regReferencesHref = /^#(.+?)$/, regReferencesBegin = /^(\w+?)\./, styleOrScript = ['style', 'script'], generateIDchars = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ], maxIDindex = generateIDchars.length - 1; /** * Remove unused and minify used IDs * (only if there are no any <style> or <script>). * * @param {Object} item current iteration item * @param {Object} params plugin params * * @author Kir Belevich */ exports.fn = function(data, params) { var currentID, currentIDstring, IDs = Object.create(null), referencesIDs = Object.create(null), idPrefix = 'id-', // prefix IDs so that values like '__proto__' don't break the work hasStyleOrScript = false; /** * Bananas! * * @param {Array} items input items * @return {Array} output items */ function monkeys(items) { for (var i = 0; i < items.content.length && !hasStyleOrScript; i++) { var item = items.content[i], match; // check if <style> of <script> presents if (item.isElem(styleOrScript)) { hasStyleOrScript = true; continue; } // …and don't remove any ID if yes if (item.isElem()) { item.eachAttr(function(attr) { var key; // save IDs if (attr.name === 'id') { key = idPrefix + attr.value; if (key in IDs) { item.removeAttr('id'); } else { IDs[key] = item; } } // save IDs url() references else if (referencesProps.indexOf(attr.name) > -1) { match = attr.value.match(regReferencesUrl); if (match) { key = idPrefix + match[2]; if (referencesIDs[key]) { referencesIDs[key].push(attr); } else { referencesIDs[key] = [attr]; } } } // save IDs href references else if ( attr.local === 'href' && (match = attr.value.match(regReferencesHref)) || attr.name === 'begin' && (match = attr.value.match(regReferencesBegin)) ) { key = idPrefix + match[1]; if (referencesIDs[key]) { referencesIDs[key].push(attr); } else { referencesIDs[key] = [attr]; } } }); } // go deeper if (item.content) { monkeys(item); } } return items; } data = monkeys(data); if (hasStyleOrScript) { return data; } var idKey; for (var k in referencesIDs) { if (IDs[k]) { idKey = k; k = k.replace(idPrefix, ''); // replace referenced IDs with the minified ones if (params.minify) { currentIDstring = getIDstring(currentID = generateID(currentID), params); IDs[idKey].attr('id').value = currentIDstring; referencesIDs[idKey].forEach(function(attr) { attr.value = attr.value .replace('#' + k, '#' + currentIDstring) .replace(k + '.', currentIDstring + '.'); }); idKey = idPrefix + k; } // don't remove referenced IDs delete IDs[idKey]; } } // remove non-referenced IDs attributes from elements if (params.remove) { for(var ID in IDs) { IDs[ID].removeAttr('id'); } } return data; }; /** * Generate unique minimal ID. * * @param {Array} [currentID] current ID * @return {Array} generated ID array */ function generateID(currentID) { if (!currentID) return [0]; currentID[currentID.length - 1]++; for(var i = currentID.length - 1; i > 0; i--) { if (currentID[i] > maxIDindex) { currentID[i] = 0; if (currentID[i - 1] !== undefined) { currentID[i - 1]++; } } } if (currentID[0] > maxIDindex) { currentID[0] = 0; currentID.unshift(0); } return currentID; } /** * Get string from generated ID array. * * @param {Array} arr input ID array * @return {String} output ID string */ function getIDstring(arr, params) { var str = params.prefix; arr.forEach(function(i) { str += generateIDchars[i]; }); return str; }
Texto alterado
Abrir arquivo
'use strict'; exports.type = 'full'; exports.active = true; exports.description = 'removes unused IDs and minifies used'; exports.params = { remove: true, minify: true, prefix: '', preserve: [], force: false }; var referencesProps = new Set(require('./_collections').referencesProps), regReferencesUrl = /\burl\(("|')?#(.+?)\1\)/, regReferencesHref = /^#(.+?)$/, regReferencesBegin = /^(\w+?)\./, styleOrScript = ['style', 'script'], generateIDchars = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ], maxIDindex = generateIDchars.length - 1; /** * Remove unused and minify used IDs * (only if there are no any <style> or <script>). * * @param {Object} item current iteration item * @param {Object} params plugin params * * @author Kir Belevich */ exports.fn = function(data, params) { var currentID, currentIDstring, IDs = new Map(), referencesIDs = new Map(), hasStyleOrScript = false, preserveIDs = new Set(Array.isArray(params.preserve) ? params.preserve : params.preserve ? [params.preserve] : []), idValuePrefix = '#', idValuePostfix = '.'; /** * Bananas! * * @param {Array} items input items * @return {Array} output items */ function monkeys(items) { for (var i = 0; i < items.content.length && !hasStyleOrScript; i++) { var item = items.content[i]; // quit if <style> of <script> presents ('force' param prevents quitting) if (!params.force && item.isElem(styleOrScript)) { hasStyleOrScript = true; continue; } // …and don't remove any ID if yes if (item.isElem()) { item.eachAttr(function(attr) { var key, match; // save IDs if (attr.name === 'id') { key = attr.value; if (IDs.has(key)) { item.removeAttr('id'); // remove repeated id } else { IDs.set(key, item); } return; } // save references if (referencesProps.has(attr.name) && (match = attr.value.match(regReferencesUrl))) { key = match[2]; // url() reference } else if ( attr.local === 'href' && (match = attr.value.match(regReferencesHref)) || attr.name === 'begin' && (match = attr.value.match(regReferencesBegin)) ) { key = match[1]; // href reference } if (key) { var ref = referencesIDs.get(key) || []; ref.push(attr); referencesIDs.set(key, ref); } }); } // go deeper if (item.content) { monkeys(item); } } return items; } data = monkeys(data); if (hasStyleOrScript) { return data; } for (var ref of referencesIDs) { var key = ref[0]; if (IDs.has(key)) { // replace referenced IDs with the minified ones if (params.minify && !preserveIDs.has(key)) { currentIDstring = getIDstring(currentID = generateID(currentID), params); IDs.get(key).attr('id').value = currentIDstring; for (var attr of ref[1]) { attr.value = attr.value.includes(idValuePrefix) ? attr.value.replace(idValuePrefix + key, idValuePrefix + currentIDstring) : attr.value.replace(key + idValuePostfix, currentIDstring + idValuePostfix); } } // don't remove referenced IDs IDs.delete(key); } } // remove non-referenced IDs attributes from elements if (params.remove) { for(var keyElem of IDs) { if (!preserveIDs.has(keyElem[0])) { keyElem[1].removeAttr('id'); } } } return data; }; /** * Generate unique minimal ID. * * @param {Array} [currentID] current ID * @return {Array} generated ID array */ function generateID(currentID) { if (!currentID) return [0]; currentID[currentID.length - 1]++; for(var i = currentID.length - 1; i > 0; i--) { if (currentID[i] > maxIDindex) { currentID[i] = 0; if (currentID[i - 1] !== undefined) { currentID[i - 1]++; } } } if (currentID[0] > maxIDindex) { currentID[0] = 0; currentID.unshift(0); } return currentID; } /** * Get string from generated ID array. * * @param {Array} arr input ID array * @return {String} output ID string */ function getIDstring(arr, params) { var str = params.prefix; return str + arr.map(i => generateIDchars[i]).join(''); }
Encontrar Diferença