Created
December 20, 2018 05:31
-
-
Save phiSgr/c308f80a0a95dcc0bc66706be4c928b4 to your computer and use it in GitHub Desktop.
Changing BridgeBase Java handviewer to the js version
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
// For the documentation on the js handviewer, see http://www.bridgebase.com/tools/hvdoc.html | |
const convertParam = function(key, value) { | |
switch (key) { | |
case "north": | |
return ["n", value.replace(/^!\*!North\*/, "")] | |
case "east": | |
return ["e", value.replace(/^!\*!East\*/, "")] | |
case "west": | |
return ["w", value.replace(/^!\*!West\*/, "")] | |
case "south": | |
let v = value.replace(/^!\*!South\*/, "") | |
// fixing the typo in 2ov1a.html | |
if (v[0] !== 's' && v[0] !== 'S') v = 's' + v.substr(1) | |
return ["s", v] | |
case "dealer": | |
return ["d", value[0]] | |
case "bidding": | |
return ["a", value] | |
case "bblue": | |
case "bred": | |
case "bgreen": | |
return null | |
default: | |
console.log("Encountered unknown key", key, value) | |
return null | |
} | |
} | |
const convertHandViewer = function(a) { | |
const queryString = Array.from(a.childNodes) | |
.filter(n => n.tagName === "PARAM") | |
.map(n => convertParam(n.getAttribute("name"), n.getAttribute("value"))) | |
.filter(kv => kv !== null) | |
.map(([k, v]) => k + '=' + v) | |
.join('&') | |
const iframe = document.createElement("iframe") | |
iframe.setAttribute("src", "https://www.bridgebase.com/tools/handviewer.html?" + queryString) | |
iframe.setAttribute("width", a.getAttribute("width")) | |
iframe.setAttribute("height", a.getAttribute("height")) | |
return iframe | |
} | |
const handViewerApplets = Array.from(document.getElementsByTagName("applet")) | |
.filter(a => a.attributes["code"].value === "dealdoc.class") | |
handViewerApplets.forEach(function(a) { | |
const iframeViewer = convertHandViewer(a) | |
a.parentElement.replaceChild(iframeViewer, a) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Improving 2/1 Game Force is a great series of articles on bridge bidding. Unfortunately the website uses Java applets, a deprecated technology, to display the hands and sequences, making viewing very difficult. This snippet converts the data in the applet nodes to create iframes of the new js viewer.