Created
December 24, 2019 21:35
-
-
Save rjames86/893a3bf25c407e6835a57a228ecdecc3 to your computer and use it in GitHub Desktop.
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
function getMeta(metaName) { | |
const metas = document.getElementsByTagName('meta'); | |
for (let i = 0; i < metas.length; i++) { | |
if (metas[i].getAttribute('property') === metaName) { | |
return metas[i].getAttribute('content'); | |
} | |
} | |
return ''; | |
} | |
const description = getMeta('og:description'); | |
// [97, 122] | |
const lowerCase = []; | |
// [65, 90] | |
const upperCase = []; | |
for (let i = 97; i <= 122; i++) { | |
lowerCase.push(i); | |
} | |
for (let i = 65; i <= 90; i++) { | |
upperCase.push(i); | |
} | |
const getRot13Val = asciiVal => { | |
let newVal; | |
if (upperCase.includes(asciiVal)) { | |
const newIndex = (upperCase.indexOf(asciiVal) + 13) % upperCase.length; | |
newVal = upperCase[newIndex]; | |
} else if (lowerCase.includes(asciiVal)) { | |
const newIndex = (lowerCase.indexOf(asciiVal) + 13) % lowerCase.length; | |
newVal = lowerCase[newIndex]; | |
} else { | |
newVal = asciiVal; | |
} | |
return String.fromCharCode(newVal); | |
} | |
const convertToRot13 = inputString => { | |
let outputString = ''; | |
for (const s of inputString) { | |
const asciiVal = s.charCodeAt(0); | |
outputString += getRot13Val(asciiVal); | |
} | |
return outputString; | |
} | |
const converted = convertToRot13(description) | |
// Call completion to finish | |
completion(converted); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment