Last active
November 27, 2017 17:31
-
-
Save ember-rose/3f836e4e46dd7c01ee20dc26b955dd6a to your computer and use it in GitHub Desktop.
Facebook Polyam Userscript
This file contains hidden or 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 (document) { | |
function augmentRelationSelect() { | |
const select = document.querySelector('#family-relationships-pagelet .relationSelector') | |
if (select) { | |
makeOption(select, 163, 'Husband') | |
makeOption(select, 164, 'Wife') | |
makeOption(select, 223, 'Partner (female)') | |
makeOption(select, 224, 'Partner (male)') | |
makeOption(select, 241, 'Partner (gender neutral)') | |
makeOption(select, 240, 'Family Member') | |
makeOption(select, 242, 'Pet (gender neutral)') | |
} | |
} | |
function makeOption(select, id, name) { | |
if (!anyChild(select, function (node) { | |
return node.nodeName === 'option' && node.getAttribute('value') === id.toString() | |
})) { | |
const option = document.createElement('option') | |
option.appendChild(document.createTextNode(name)) | |
option.setAttribute('value', id) | |
select.appendChild(option) | |
} | |
} | |
function anyChild(node, f) { | |
if (node.hasChildNodes()) { | |
const nodeList = node.childNodes | |
for (var i = 0; i < nodeList.length; i++) { | |
if (nodeList.item(i).nodeType === Node.ELEMENT_NODE) { | |
if (f(node)) { | |
return true | |
} | |
} | |
} | |
} | |
return false | |
} | |
augmentRelationSelect() | |
})(document) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment