Facebook Profile Marketplace Link

Adds a link to a user's Marketplace profile on their main page

目前為 2023-10-12 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Facebook Profile Marketplace Link 
// @description  Adds a link to a user's Marketplace profile on their main page
// @match        https://www.facebook.com/*
// @version      0.2
// @author       mica
// @namespace    greasyfork.org/users/12559
// @license      MIT
// @grant        GM_xmlhttpRequest
// ==/UserScript==



function makeLink(id) {
    var link = 'https://www.facebook.com/marketplace/profile/' + id;
    var e = document.querySelectorAll('span');
    for (var i = 0; i < e.length; i++) {
        if (e[i].innerText == 'More') {
            loc = e[i].closest('div[aria-haspopup]').parentNode;
            break;
        }
    }
    loc.insertAdjacentHTML('afterend',`
        <a style="
            position: relative;
            top: 29px;
            color: rgb(101, 103, 107);
            font-size: 15px;
            font-weight: 600;
        " id="mpLink" href="${link}">Marketplace</a>
    `);
}

function getId() {
    if (new URLSearchParams(location.search).get('id')) {
        makeLink(new URLSearchParams(location.search).get('id'));
    } else {
        GM_xmlhttpRequest({
            method: "GET",
            url: location.origin + location.pathname,
            onload: (response) => {
                makeLink(response.responseText.match(/(?<=userID":")\d*/g)[0]);
            }  
        });
    }
}

function checkProfile() {
    if (!location.pathname.match(/^\/$|\/friends*|\/groups*|\/messages*|\/marketplace*|\/watch*|\/reel*|\/events*|\/gaming*|\/memories*|\/saved*|\/fundraisers*|\/pages*|\/settings*|\/help*|\/ads*/g)) {
        setTimeout(() => {
            if (!document.getElementById('mpLink')) {
                var e = document.querySelectorAll('circle');
                for (var i = 0; i < e.length; i++) {
                    if (e[i].getAttribute('cx') == 84) {
                        getId();
                        break;
                    }
                }
            }
        }, 600);
    }
}

var url;
setInterval(() => {
    if (url != location.href) {
        url = location.href;
        checkProfile();
    }
}, 200);