|
Notification.requestPermission().then(function(status) { |
|
if (status === "denied") |
|
console.log("Notifications denied. Try clicking the website's little lock & see if you can allow from there") |
|
else |
|
console.log(`Notifications Permission: ${status}`) |
|
}) |
|
|
|
function canSendNotification() { |
|
return (window.Notification && Notification.permission === "granted") |
|
} |
|
|
|
function notifyOrAlert(message) { |
|
if (canSendNotification()) |
|
new Notification(message) |
|
else |
|
alert(message) |
|
} |
|
|
|
function getLastProfileUrl() { |
|
var rows = document.querySelectorAll(".userrow-bucket > a") |
|
if (rows.length == 0) |
|
return null |
|
else |
|
return rows[rows.length - 1].href |
|
} |
|
|
|
function getAllDisplayedProfilesAsLinks() { |
|
return document.querySelectorAll(".userrow-bucket > a") |
|
} |
|
|
|
// actually, this is all profiles right not |
|
function countOfDisplayedProfiles() { |
|
return getAllDisplayedProfilesAsLinks().length |
|
} |
|
|
|
var lastProfileUrl = getLastProfileUrl(); |
|
var repeatedCount = 0 |
|
|
|
// Stop Scrolling when, after scrolling down, the last profile |
|
// at the bottom is the same, 3 times in a row |
|
function doneScrolling() { |
|
var currentLastProfileUrl = getLastProfileUrl() |
|
if (currentLastProfileUrl == lastProfileUrl) { |
|
repeatedCount++ |
|
return (repeatedCount >= 3) |
|
} else { |
|
window.repeatedCount = 0 |
|
window.lastProfileUrl = currentLastProfileUrl |
|
return false |
|
} |
|
} |
|
|
|
// timeout = 500? sure, we'll try "swiping" twice a second |
|
function scrollDown(callback) { |
|
window.scrollBy(0,10000); |
|
setTimeout(callback, 500) |
|
} |
|
|
|
function finishScrolling(done) { |
|
// set the target of all to be _blank now that they're all loaded |
|
// so I won't accidentally click and lose all of the loaded users |
|
getAllDisplayedProfilesAsLinks().forEach(a => a.setAttribute("target", "_blank")) |
|
|
|
notifyOrAlert(`Finished Scrolling (${countOfDisplayedProfiles()})`) |
|
done() |
|
} |
|
|
|
function scrollToBottomOfWhoLikesYou(done) { |
|
scrollDown(function() { |
|
if (doneScrolling()) |
|
finishScrolling(done) |
|
else |
|
scrollToBottomOfWhoLikesYou(done) |
|
}) |
|
} |
|
|
|
function scrollUntilGivenNumberOfUsers(count, done) { |
|
scrollDown(function() { |
|
if (countOfDisplayedProfiles() >= count || doneScrolling()) |
|
finishScrolling(done) |
|
else |
|
scrollUntilGivenNumberOfUsers(count, done) |
|
}) |
|
} |
|
|
|
// So I can check and see how far I am thru the whole list... |
|
function howFarAmI(nameAndAge) { |
|
var textToSearch = nameAndAge |
|
// get the part with the name + age |
|
var rows = document.querySelectorAll(".userrow-bucket > a .userInfo-username") |
|
// find all matching (incase many) |
|
var matchingIndices = [] |
|
for (var i = 0; i < rows.length - 1; i++) { |
|
if (rows[i].innerText == textToSearch) |
|
matchingIndices.push(i) |
|
} |
|
if (matchingIndices.length == 0) { |
|
console.log(`No people found for: ${textToSearch}`) |
|
} else if (matchingIndices.length > 1) { |
|
console.log(`Found ${matchingIndices.length} potential matches`) |
|
} else { |
|
var matchingIndex = matchingIndices[0] |
|
console.log(`Found "${textToSearch}" @ ${matchingIndex} out of total of ${rows.length}`) |
|
console.log(`I guess you have ${matchingIndex} more to go!`) |
|
} |
|
} |
|
|
|
function userInfoFromRow(anchor) { |
|
try { |
|
const href = anchor.href |
|
const username = anchor.pathname.split("/").pop() |
|
const [name, age] = anchor.querySelector(".userInfo-username-name").innerText.split(", ") |
|
const [city, state] = anchor.querySelector(".userInfo-meta-location").innerText.split(", ") |
|
const matchPercentage = parseInt(anchor.querySelector(".match-info-percentage").innerText) |
|
const isOnline = anchor.querySelector(".onlinedot") != null |
|
const messagedMe = anchor.querySelector(".i-messages") != null |
|
return { href, username, name, age, city, state, matchPercentage, isOnline, messagedMe } |
|
} catch (e) { |
|
console.log("Error parsing anchor", anchor, e) |
|
} |
|
} |
|
|
|
// callback is called with (userInfo, rowAnchor) |
|
function forEachUserRow(callback) { |
|
getAllDisplayedProfilesAsLinks().forEach(anchor => { |
|
var info = userInfoFromRow(anchor) |
|
if (info != null) |
|
callback(info, anchor) |
|
}) |
|
} |
|
|
|
const hideUser = (anchor) => anchor.style.display = "none" |
|
const showUser = (anchor) => anchor.style.display = "block" |
|
|
|
function showUsers(matcher) { |
|
forEachUserRow((info, anchor) => { |
|
if (matcher(info)) |
|
showUser(anchor) |
|
else |
|
hideUser(anchor) |
|
}) |
|
} |
|
|
|
function hideUsers(matcher) { |
|
forEachUserRow((info, anchor) => { |
|
if (matcher(info)) |
|
hideUser(anchor) |
|
else |
|
showUser(anchor) |
|
}) |
|
} |
|
|
|
function hideUnderPercentage(percentageNumber) { |
|
hideUsers(user => user.matchPercentage < percentageNumber) |
|
} |
|
|
|
// city only, e.g. "Seattle" |
|
function hideThoseNotInCity(city) { |
|
hideUsers(user => user.city != city) |
|
} |
|
|
|
function hideThoseAboveAge(ageNumber) { |
|
hideUsers(user => user.age > ageNumber) |
|
} |