Skip to content

Instantly share code, notes, and snippets.

@rjames86
Created December 24, 2019 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjames86/893a3bf25c407e6835a57a228ecdecc3 to your computer and use it in GitHub Desktop.
Save rjames86/893a3bf25c407e6835a57a228ecdecc3 to your computer and use it in GitHub Desktop.
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