Skip to content

Instantly share code, notes, and snippets.

@jcunews
Created June 16, 2017 22:37
Show Gist options
  • Save jcunews/acc9ebb91e818bbce91e8cad532cf8c9 to your computer and use it in GitHub Desktop.
Save jcunews/acc9ebb91e818bbce91e8cad532cf8c9 to your computer and use it in GitHub Desktop.
Opera Skin Images Previewer
<html>
<head>
<!--
Copyright (c) 2017, jcunews.
https://www.reddit.com/user/jcunews1/
Licensed under MIT license.
-->
<title>Opera Skin Images Previewer</title>
<style>
body {
background-color: #fff;
}
#skinIni {
display: none;
}
#tbl {
background-color: #aaa;
}
th {
background-color: #000;
color: #fff;
}
td {
background-color:#eee;
}
#tbl div {
width: -o-skin;
height: -o-skin;
}
</style>
<script>
var skinIniLoaded = false, skinData = "";
var errMsg2 = " The skin.txt file must originally be extracted from one of the skin ZIP files in the skin folder of the Opera profile folder, then renamed to skin.txt. The skin ZIP file should be the one that is used for the current Opera browser skin.";
function notifySkinIniLoaded() {
skinIniLoaded = true;
}
function parseSkinIni() {
var a, b, c, d, e, f, g, h, i, nl = "", txt = skinIni.document.querySelector("body>pre");
var errMsg = "Invalid skin.txt file." + errMsg2;
if (!txt || (txt.childElementCount !== 0) || (txt.childNodes.length !== 1)) {
info.textContent = errMsg;
return;
}
txt = txt.firstChild.data;
a = txt.indexOf("[Images]");
if (a < 0) {
info.textContent = errMsg;
return;
}
b = txt.indexOf("\n", a+1);
if (b < 0) {
info.textContent = errMsg;
return;
}
if (b > 0) {
if (txt.charAt(b-1) === "\r") {
nl = "\r\n";
} else nl = "\n";
} else nl = "\n";
b = txt.indexOf("[", a+1);
if (b < 0) b = txt.length;
txt = txt.substring(a, b).split(nl);
while (txt.length && (txt[0].trim() === "")) txt.splice(0);
while (txt.length && (txt[txt.length-1].trim() === "")) txt.splice(txt.length-1);
info.style.display = "none";
//populate table
b = txt;
e = 1;
tbl.appendChild(document.createElement("thead")).innerHTML = "<thead><th>Name</th><th>Size</th><th>Image</th></thead>";
f = tbl.appendChild(document.createElement("tbody"));
for (c = 0; c < b.length; c++) {
d = b[c].trim();
if (d.charAt(0) !== ";") {
d = b[c].substr(0,b[c].indexOf("=")).trim();
if (d !== "") {
a = f.appendChild(document.createElement("tr"));
g = a.appendChild(document.createElement("td"));
g.innerText = d;
g = a.appendChild(document.createElement("td"));
g.className = "size";
g.style.cssText = "min-width:7ex;text-align:center";
h = a.appendChild(document.createElement("td"));
i = h.appendChild(document.createElement("div"));
i.className = "icon";
i.style.backgroundImage = "-o-skin('"+d+"')";
e=1;
} else if ((e !== 0) && (c !== (b.length-1))) {
a = f.appendChild(document.createElement("tr"));
g = a.appendChild(document.createElement("td"));
g.setAttribute("colspan", "3");
g.style.cssText = "line-height:2px;background:inherit";
e = 0;
}
}
}
a = Array.prototype.slice.call(tbl.rows);
b = 0;
(function getIconSize() {
c = a[b].querySelector(".icon");
if (c) {
d = a[b].querySelector(".size");
d.innerText = c.offsetWidth + "x" + c.offsetHeight;
}
b++;
if (b < a.length) setTimeout(getIconSize, 20);
})();
}
function waitData(){
if (skinIniLoaded) {
if (skinIni.document.querySelector('link[rel="stylesheet"][href*="/styles/error.css"]')) {
info.textContent = "Failed to load skin.txt file." + errMsg2;
return;
}
info.textContent = "Parsing skin.txt data...";
setTimeout(parseSkinIni, 0);
} else setTimeout(waitData, 500);
}
addEventListener("load", function(){
info.textContent = "Waiting for skin.txt data to load...";
waitData();
});
</script>
</head>
<body>
<iframe id=skinIni src="skin.txt" onload="notifySkinIniLoaded()"></iframe>
<div id="info">Initializing... (if this text doesn't change within a second, it means that something is interfering. e.g. disabled JavaScript or browser addons)</div>
<table id=tbl cellspacing=1 cellpadding=1 bgcolor=#aaaaaa></table>
<div></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment