Skip to content

Instantly share code, notes, and snippets.

@bramus
Last active September 20, 2024 07:01
Show Gist options
  • Save bramus/d8bce55dab1881cde18aa2169c66ac33 to your computer and use it in GitHub Desktop.
Save bramus/d8bce55dab1881cde18aa2169c66ac33 to your computer and use it in GitHub Desktop.

Revisions

  1. bramus revised this gist Nov 25, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bookmarklet.md
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    🚚 The bookmarklet has moved to [https://github.com/bramus/mastodon-profile-redirect/tree/main/bookmarklet](https://github.com/bramus/mastodon-profile-redirect/tree/main/bookmarklet)
    🚚 The bookmarklet has moved to [https://github.com/bramus/mastodon-profile-redirect/](https://github.com/bramus/mastodon-profile-redirect/)
  2. bramus revised this gist Nov 24, 2022. 2 changed files with 1 addition and 36 deletions.
    36 changes: 0 additions & 36 deletions bookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -1,36 +0,0 @@
    javascript:(function(){
    const MY_MASTO_LOCAL_DOMAIN = 'front-end.social'; /* 👈 Change this value */
    const MY_MASTO_WEB_DOMAIN = MY_MASTO_LOCAL_DOMAIN; /* 👈 Only change this value if your Masto host is hosted an different domain than the LOCAL_DOMAIN */

    function tryAndGetUserName() {
    /* Profile with a moved banner (e.g. https://mastodon.social/@bramus): follow that link */
    const userNewProfile = document.querySelector('.moved-account-banner .button')?.getAttribute('href');
    if (userNewProfile) {
    return userNewProfile.substring(2);
    }

    /* Profile page, e.g. https://fediverse.zachleat.com/@zachleat and https://front-end.social/@mia */
    const userFromProfilePage = document.querySelector('meta[property="profile:username"]')?.getAttribute('content');
    if (userFromProfilePage) {
    /* Don’t return if already watching on own LOCAL_DOMAIN instance */
    if (window.location.host === MY_MASTO_LOCAL_DOMAIN) return null;
    return userFromProfilePage;
    };

    /* Message detail, e.g. https://front-end.social/@mia/109348973362020954 and https://bell.bz/@andy/109392510558650993 and https://bell.bz/@andy/109392510558650993 */
    const userFromDetailPage = document.querySelector('.detailed-status .display-name__account')?.innerText;
    if (userFromDetailPage) return userFromDetailPage.substring(1);

    return null;
    };

    let user = tryAndGetUserName();
    if (!user) return;

    /* Trim off @domain suffix in case it matches with MY_MASTO_LOCAL_DOMAIN. This due to https://github.com/mastodon/mastodon/issues/21469 */
    if (user.endsWith(`@${MY_MASTO_LOCAL_DOMAIN}`)) {
    user = user.substring(0, user.length - `@${MY_MASTO_LOCAL_DOMAIN}`.length);
    }

    window.location.href = `https://${MY_MASTO_WEB_DOMAIN}/@${user}`;
    })();
    1 change: 1 addition & 0 deletions bookmarklet.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    🚚 The bookmarklet has moved to [https://github.com/bramus/mastodon-profile-redirect/tree/main/bookmarklet](https://github.com/bramus/mastodon-profile-redirect/tree/main/bookmarklet)
  3. bramus revised this gist Nov 23, 2022. 1 changed file with 13 additions and 10 deletions.
    23 changes: 13 additions & 10 deletions bookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -6,28 +6,31 @@ javascript:(function(){
    /* Profile with a moved banner (e.g. https://mastodon.social/@bramus): follow that link */
    const userNewProfile = document.querySelector('.moved-account-banner .button')?.getAttribute('href');
    if (userNewProfile) {
    /* Trim off @domain suffix in case it matches with MY_MASTO_LOCAL_DOMAIN. This due to https://github.com/mastodon/mastodon/issues/21469 */
    if (userNewProfile.endsWith(`@${MY_MASTO_LOCAL_DOMAIN}`)) {
    return userNewProfile.substring(2, userNewProfile.length - `@${MY_MASTO_LOCAL_DOMAIN}`.length);
    }
    return userNewProfile.substring(2);
    }

    /* Profile, viewed on other host, e.g. https://fediverse.zachleat.com/@zachleat */
    /* Profile page, e.g. https://fediverse.zachleat.com/@zachleat and https://front-end.social/@mia */
    const userFromProfilePage = document.querySelector('meta[property="profile:username"]')?.getAttribute('content');
    if (userFromProfilePage) return userFromProfilePage;
    if (userFromProfilePage) {
    /* Don’t return if already watching on own LOCAL_DOMAIN instance */
    if (window.location.host === MY_MASTO_LOCAL_DOMAIN) return null;
    return userFromProfilePage;
    };

    /* Message detail, e.g. https://bell.bz/@andy/109392510558650993 and https://bell.bz/@andy/109392510558650993 */
    /* Message detail, e.g. https://front-end.social/@mia/109348973362020954 and https://bell.bz/@andy/109392510558650993 and https://bell.bz/@andy/109392510558650993 */
    const userFromDetailPage = document.querySelector('.detailed-status .display-name__account')?.innerText;
    if (userFromDetailPage) return userFromDetailPage.substring(1);

    return null;
    };

    /* if (window.location.host === MY_MASTO_WEB_DOMAIN) return; */

    const user = tryAndGetUserName();
    let user = tryAndGetUserName();
    if (!user) return;

    /* Trim off @domain suffix in case it matches with MY_MASTO_LOCAL_DOMAIN. This due to https://github.com/mastodon/mastodon/issues/21469 */
    if (user.endsWith(`@${MY_MASTO_LOCAL_DOMAIN}`)) {
    user = user.substring(0, user.length - `@${MY_MASTO_LOCAL_DOMAIN}`.length);
    }

    window.location.href = `https://${MY_MASTO_WEB_DOMAIN}/@${user}`;
    })();
  4. bramus revised this gist Nov 23, 2022. 1 changed file with 27 additions and 4 deletions.
    31 changes: 27 additions & 4 deletions bookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,33 @@
    javascript:(function(){
    const MY_MASTO_HOST = 'front-end.social';
    const MY_MASTO_LOCAL_DOMAIN = 'front-end.social'; /* 👈 Change this value */
    const MY_MASTO_WEB_DOMAIN = MY_MASTO_LOCAL_DOMAIN; /* 👈 Only change this value if your Masto host is hosted an different domain than the LOCAL_DOMAIN */

    if (window.location.host === MY_MASTO_HOST) return;
    function tryAndGetUserName() {
    /* Profile with a moved banner (e.g. https://mastodon.social/@bramus): follow that link */
    const userNewProfile = document.querySelector('.moved-account-banner .button')?.getAttribute('href');
    if (userNewProfile) {
    /* Trim off @domain suffix in case it matches with MY_MASTO_LOCAL_DOMAIN. This due to https://github.com/mastodon/mastodon/issues/21469 */
    if (userNewProfile.endsWith(`@${MY_MASTO_LOCAL_DOMAIN}`)) {
    return userNewProfile.substring(2, userNewProfile.length - `@${MY_MASTO_LOCAL_DOMAIN}`.length);
    }
    return userNewProfile.substring(2);
    }

    const user = document.querySelector('meta[property="profile:username"]')?.getAttribute('content');
    /* Profile, viewed on other host, e.g. https://fediverse.zachleat.com/@zachleat */
    const userFromProfilePage = document.querySelector('meta[property="profile:username"]')?.getAttribute('content');
    if (userFromProfilePage) return userFromProfilePage;

    /* Message detail, e.g. https://bell.bz/@andy/109392510558650993 and https://bell.bz/@andy/109392510558650993 */
    const userFromDetailPage = document.querySelector('.detailed-status .display-name__account')?.innerText;
    if (userFromDetailPage) return userFromDetailPage.substring(1);

    return null;
    };

    /* if (window.location.host === MY_MASTO_WEB_DOMAIN) return; */

    const user = tryAndGetUserName();
    if (!user) return;

    window.location.href = `https://${MY_MASTO_HOST}/@${user}`;
    window.location.href = `https://${MY_MASTO_WEB_DOMAIN}/@${user}`;
    })();
  5. bramus created this gist Nov 21, 2022.
    10 changes: 10 additions & 0 deletions bookmarklet.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    javascript:(function(){
    const MY_MASTO_HOST = 'front-end.social';

    if (window.location.host === MY_MASTO_HOST) return;

    const user = document.querySelector('meta[property="profile:username"]')?.getAttribute('content');
    if (!user) return;

    window.location.href = `https://${MY_MASTO_HOST}/@${user}`;
    })();