Diff
checker
テキスト
テキスト
画像
ドキュメント
Excel
フォルダ
Legal
Enterprise
デスクトップ
料金
ログイン
Diffchecker デスクトップのダウンロード
テキスト比較
2 つのテキスト ファイルの違いを見つける
ツール
履歴
ライブエディター
空白の変更を非表示
未変更行を折りたたむ
折り返しなし
レイアウト
分割
統合
比較精度
スマート
単語
文字
テキストスタイル
外観を変更
シンタックスハイライト
構文を選択
無視
テキスト変換
最初の差分へ移動
入力を編集
Diffchecker Desktop
Diffcheckerを実行する最も安全な方法。Diffchecker Desktopアプリを入手:あなたの差分はコンピューターから出ることはありません!
Desktopを入手
Untitled diff
作成日
9 年前
差分は期限切れになりません
クリア
エクスポート
共有
説明
94 削除
行
合計
削除
文字
合計
削除
この機能を引き続き使用するには、アップグレードしてください
Diff
checker
Pro
価格を見る
209 行
すべてコピー
57 追加
行
合計
追加
文字
合計
追加
この機能を引き続き使用するには、アップグレードしてください
Diff
checker
Pro
価格を見る
174 行
すべてコピー
'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,
コピー
コピー済み
コピー
コピー済み
prefix: ''
prefix: ''
,
preserve: [],
force: false
};
};
コピー
コピー済み
コピー
コピー済み
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) {
コピー
コピー済み
コピー
コピー済み
var currentID,
var currentID,
currentIDstring,
currentIDstring,
コピー
コピー済み
コピー
コピー済み
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) {
コピー
コピー済み
コピー
コピー済み
for (var i = 0; i < items.content.length && !hasStyleOrScript; i++) {
for (var i = 0; i < items.content.length && !hasStyleOrScript; i++) {
コピー
コピー済み
コピー
コピー済み
var item = items.content[i]
;
var item = items.content[i]
,
match
;
コピー
コピー済み
コピー
コピー済み
//
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;
}
}
コピー
コピー済み
コピー
コピー済み
// …and don't remove any ID if yes
// …and don't remove any ID if yes
if (item.isElem()) {
if (item.isElem()) {
コピー
コピー済み
コピー
コピー済み
item.eachAttr(function(attr) {
item.eachAttr(function(attr) {
コピー
コピー済み
コピー
コピー済み
var key
;
var key
, match;
// save IDs
// save IDs
if (attr.name === 'id') {
if (attr.name === 'id') {
コピー
コピー済み
コピー
コピー済み
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 {
コピー
コピー済み
コピー
コピー済み
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];
}
}
}
コピー
コピー済み
コピー
コピー済み
return;
}
}
コピー
コピー済み
コピー
コピー済み
// 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))
) {
) {
コピー
コピー済み
コピー
コピー済み
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);
}
}
});
});
コピー
コピー済み
コピー
コピー済み
}
}
コピー
コピー済み
コピー
コピー済み
// go deeper
// go deeper
if (item.content) {
if (item.content) {
monkeys(item);
monkeys(item);
}
}
}
}
コピー
コピー済み
コピー
コピー済み
return items;
return items;
コピー
コピー済み
コピー
コピー済み
}
}
data = monkeys(data);
data = monkeys(data);
if (hasStyleOrScript) {
if (hasStyleOrScript) {
return data;
return data;
}
}
コピー
コピー済み
コピー
コピー済み
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
コピー
コピー済み
コピー
コピー済み
if (params.minify
) {
if (params.minify
&& !preserveIDs.has(key)
) {
currentIDstring = getIDstring(currentID = generateID(currentID), params);
currentIDstring = getIDstring(currentID = generateID(currentID), params);
コピー
コピー済み
コピー
コピー済み
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 + '.');
});
コピー
コピー済み
コピー
コピー済み
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);
}
}
}
コピー
コピー済み
コピー
コピー済み
// don't remove referenced IDs
// don't remove referenced IDs
コピー
コピー済み
コピー
コピー済み
delete
IDs[idKey]
;
IDs.
delete
(key)
;
}
}
}
}
コピー
コピー済み
コピー
コピー済み
// remove non-referenced IDs attributes from elements
// remove non-referenced IDs attributes from elements
if (params.remove) {
if (params.remove) {
コピー
コピー済み
コピー
コピー済み
for(var
keyElem of
IDs) {
for(var
ID in
IDs) {
if (!preserveIDs.has(keyElem[0])) {
IDs[ID
].removeAttr('id');
keyElem[1
].removeAttr('id');
}
}
}
コピー
コピー済み
コピー
コピー済み
}
}
コピー
コピー済み
コピー
コピー済み
return data;
return data;
コピー
コピー済み
コピー
コピー済み
};
};
/**
/**
* 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) {
コピー
コピー済み
コピー
コピー済み
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]++;
}
}
}
}
}
}
コピー
コピー済み
コピー
コピー済み
if (currentID[0] > maxIDindex) {
if (currentID[0] > maxIDindex) {
currentID[0] = 0;
currentID[0] = 0;
currentID.unshift(0);
currentID.unshift(0);
}
}
コピー
コピー済み
コピー
コピー済み
return currentID;
return currentID;
コピー
コピー済み
コピー
コピー済み
}
}
/**
/**
* 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) {
コピー
コピー済み
コピー
コピー済み
var str = params.prefix;
var str = params.prefix;
コピー
コピー済み
コピー
コピー済み
return
str +
arr.map(i =>
generateIDchars[i]
).join('');
arr.forEach(function(i) {
str +
=
generateIDchars[i]
;
});
return str;
}
}
保存された差分
原文
ファイルを開く
'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; }
変更されたテキスト
ファイルを開く
'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(''); }
違いを見つける