Skip to content

Instantly share code, notes, and snippets.

@rirufa
Last active October 9, 2020 09:44
Show Gist options
  • Save rirufa/2d2e766609dcd61f53109eba97fac069 to your computer and use it in GitHub Desktop.
Save rirufa/2d2e766609dcd61f53109eba97fac069 to your computer and use it in GitHub Desktop.
twitterのDMグループにユーザーをまとめて追加する奴
getElementsByXPath = function(expression, parentElement) {
var r = []
var x = document.evaluate(expression, parentElement || document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
for (var i = 0, l = x.snapshotLength; i < l; i++) {
r.push(x.snapshotItem(i))
}
return r
}
//ここにユーザーネームを追加する
usernames = ["@oqoobo","@145pokpok","@test","@test2","@gigazine"];
//追加できなかったユーザーネームの一覧
failed_names = [];
for(username of usernames)
{
var element = document.querySelector('input[placeholder="ユーザーを検索"]');
element.value= username;
element = getElementsByXPath('//form[@aria-label="ユーザーを検索"]//span[text()="'+ username + '"]');
if(element.length == 0)
failed_names.push(username);
else
element[0].click();
}
alert("add usernames. It print usernames which failed to add in console");
console.log(failed_names);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment