Last active
April 3, 2016 07:45
-
-
Save JavaScript-Packer/60848b0a2ca33aea89da to your computer and use it in GitHub Desktop.
Compare older list to a newer list to see changes (what is new and what is now gone). Working on a bookmarklet for FaceBook to find New Freinds and Friends that left (unfriended) you.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html><head><title>Compare 2 Lists For Differences. Changes Added To List & What Was Removed From Original List</title></head><body> | |
<script> | |
var s1 = 'Kvn Mrffy Brwn\n\ | |
Lrran Brwn Lavall\n\ | |
Rbrt Jsph\n\ | |
Wayn Brstw\n\ | |
Lrr Brwn Tschrwnsk\n\ | |
Krs Oltn\n\ | |
Paln Bckndal - Glnvw Park Scndary Schl\n\ | |
Andr Myrs\n\ | |
Sd Dsqd\n\ | |
Bvn San\n\ | |
Grgry Rbrt Slr - Ownr, Dvlpr, Dsgnr at OMGTap\n\ | |
Davd Btlr\n\ | |
Mk Razzl\n\ | |
Cathy Ealst\n\ | |
Gln Paln-Haskn\n\ | |
Dan Brtt\n\ | |
Mchal Lng\n\ | |
Jhn Ha-thn\n\ | |
Bn Strngarmd'; | |
var s2 = 'Ethann Brwn\n\ | |
Kvn Mrffy Brwn\n\ | |
Lrran Brwn Lavall\n\ | |
Rbrt Jsph\n\ | |
www.WHAK.com\n\ | |
Wayn Brstw\n\ | |
Mchal Hnt\n\ | |
Lrr Brwn Tschrwnsk\n\ | |
Krs Oltn\n\ | |
Sd Dsqd\n\ | |
Bvn San\n\ | |
Grgry Rbrt Slr - Ownr, Dvlpr, Dsgnr at OMGTap\n\ | |
Davd Btlr\n\ | |
Mk Razzl\n\ | |
www.GIFSTA.com\n\ | |
Gln Paln-Haskn\n\ | |
Dan Brtt\n\ | |
Mchal Lng\n\ | |
Jhn Ha-thn\n\ | |
Bn Strngarmd'; | |
function differces(n, l) { | |
for (var e = "" == n ? [] : n.split(/\n/), t = "" == l ? [ | |
] : l.split(/\n/), r = {}, o = {}, u = 0; u < t.length; u++) { | |
null == r[t[u]] && (r[t[u]] = { | |
"R": [], | |
"o": null | |
}), r[t[u]].R.push(u); | |
} | |
for (u = 0; u < e.length; u++) { | |
null == o[e[u]] && (o[e[u]] = { | |
"R": [], | |
"n": null | |
}), o[e[u]].R.push(u); | |
} | |
for (u in r) { | |
1 == r[u].R.length && void 0 !== o[u] && 1 == o[u].R.length && (t[r[u].R[0]] = { | |
"T": t[r[u].R[0]], | |
"X": o[u].R[0] | |
}, e[o[u].R[0]] = { | |
"T": e[o[u].R[0]], | |
"X": r[u].R[0] | |
}); | |
} | |
for (u = 0; u < t.length - 1; u++) { | |
null != t[u].T && null == t[u + 1].T && t[u].X + 1 < e.length && null == e[t[u | |
].X + 1].T && t[u + 1] == e[t[u].X + 1] && (t[u + 1] = { | |
"T": t[u + 1], | |
"X": t[u].X + 1 | |
}, e[t[u].X + 1] = { | |
"T": e[t[u].X + 1], | |
"X": u + 1 | |
}); | |
} | |
for (u = t.length - 1; u > 0; u--) { | |
null != t[u].T && null == t[u - 1].T && 0 < t[u].X && null == e[t[u].X - 1 | |
].T && t[u - 1] == e[t[u].X - 1] && (t[u - 1] = { | |
"T": t[u - 1], | |
"X": t[u].X - 1 | |
}, e[t[u].X - 1] = { | |
"T": e[t[u].X - 1], | |
"X": u - 1 | |
}); | |
} | |
if (r = "", 0 == t.length) { | |
for (o = 0; o < e.length; o++) { | |
r += "*REMOVED* " + e[o] + "\n"; | |
} | |
} else { | |
if (null == t[0].T) { | |
for (l = 0; l < e.length && null == e[l].T; l++) { | |
r += "*REMOVED* " + e[l] + "\n"; | |
} | |
} | |
for (o = 0; o < t.length; o++) { | |
if (null == t[o].T) { | |
r += "*ADDED* " + t[o] + "\n"; | |
} else { | |
for (u = "\n", l = t[o].X + 1; l < e.length && null == e[l].T; l++) { | |
u += "*REMOVED* " + e[l] + "\n"; | |
} | |
r += " " + t[o].T + u; | |
} | |
} | |
} | |
return r; | |
} | |
document.write('<h1><a href="http://www.whak.ca">WHAK.com</a>\'s List Difference Comparison Generator</h1><style>label {display:block;}</style>'+ | |
'<label>List #1 & List #2</label><textarea id="list_1" rows="20" cols="77" onmouseover="this.select();">' + s1 + | |
'<\/textarea> VERSUS <textarea onmouseover="this.select();" id="list_2" rows="20" cols="77">' + s2 + | |
'<\/textarea><label>Changes From List #1 Compared To List #2</label><textarea onmouseover="this.select();" id="results" rows="22" cols="77">' + | |
'<\/textarea><p><input type="button" onclick="results.value=differces(list_1.value, list_2.value);" value="Compare"></p>'); | |
</script> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DataURI/DataURL to test:
data:text/html,%3Chtml%3E%3Chead%3E%3Ctitle%3ECompare%202%20Lists%3C%2Ftitle%3E%3C%2Fhead%3E%3Cbody%3E%3Cscript%3Evar%20s1%3D%22Kvn%20Mrffy%20Brwn%5CnLrran%20Brwn%20Lavall%5CnRbrt%20Jsph%5CnWayn%20Brstw%5CnLrr%20Brwn%20Tschrwnsk%5CnKrs%20Oltn%5CnPaln%20Bckndal%20%2D%20Glnvw%20Park%20Scndary%20Schl%5CnAndr%20Myrs%5CnSd%20Dsqd%5CnBvn%20San%5CnGrgry%20Rbrt%20Slr%20%2D%20Ownr%2C%20Dvlpr%2C%20Dsgnr%20at%20OMGTap%5CnDavd%20Btlr%5CnMk%20Razzl%5CnCathy%20Ealst%5CnGln%20Paln%2DHaskn%5CnDan%20Brtt%5CnMchal%20Lng%5CnJhn%20Ha%2Dthn%5CnBn%20Strngarmd%22%3Bvar%20s2%3D%22Ethann%20Brwn%5CnKvn%20Mrffy%20Brwn%5CnLrran%20Brwn%20Lavall%5CnRbrt%20Jsph%5Cnwww%2EWHAK%2Ecom%5CnWayn%20Brstw%5CnMchal%20Hnt%5CnLrr%20Brwn%20Tschrwnsk%5CnKrs%20Oltn%5CnSd%20Dsqd%5CnBvn%20San%5CnGrgry%20Rbrt%20Slr%20%2D%20Ownr%2C%20Dvlpr%2C%20Dsgnr%20at%20OMG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Bl%5D%2ET%3Bl%2B%2B%29u%2B%3D%22%2AREMOVED%2A%20%22%2Be%5Bl%5D%2B%22%5Cn%22%3Br%2B%3D%22%20%22%2Bt%5Bo%5D%2ET%2Bu%7D%7Dreturn%20r%7Ddocument%2Ewrite%28%27%3Ch1%3E%3Ca%20href%3D%22http%3A%2F%2Fwww%2Ewhak%2Eca%22%3EWHAK%2Ecom%3C%2Fa%3E%5C%27s%20List%20Difference%20Comparison%20Generator%3C%2Fh1%3E%3Cstyle%3Elabel%20%7Bdisplay%3Ablock%3B%7D%3C%2Fstyle%3E%27%2B%27%3Clabel%3EList%20%231%20%26amp%3B%20List%20%232%3C%2Flabel%3E%3Ctextarea%20id%3D%22list_1%22%20rows%3D%2220%22%20cols%3D%2277%22%20onmouseover%3D%22this%2Eselect%28%29%3B%22%3E%27%2Bs1%2B%27%3C%2Ftextarea%3E%20VERSUS%20%3Ctextarea%20onmouseover%3D%22this%2Eselect%28%29%3B%22%20id%3D%22list_2%22%20rows%3D%2220%22%20cols%3D%2277%22%3E%27%2Bs2%2B%27%3C%2Ftextarea%3E%3Clabel%3EChanges%20From%20List%20%231%20Compared%20To%20List%20%232%3C%2Flabel%3E%3Ctextarea%20onmouseover%3D%22this%2Eselect%28%29%3B%22%20id%3D%22results%22%20rows%3D%2222%22%20cols%3D%2277%22%3E%27%2B%27%3C%2Ftextarea%3E%3Cp%3E%3Cinput%20type%3D%22button%22%20onclick%3D%22results%2Evalue%3Ddifferces%28list_1%2Evalue%2C%20list_2%2Evalue%29%3B%22%20value%3D%22Compare%22%3E%3C%2Fp%3E%27%29%3B%3C%2Fscript%3E%3C%2Fbody%3E%3C%2Fhtml%3E