Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Neat Url] Don't catch url with # #83

Closed
AntoineLemaire opened this issue Nov 8, 2017 · 5 comments
Closed

[Neat Url] Don't catch url with # #83

AntoineLemaire opened this issue Nov 8, 2017 · 5 comments

Comments

@AntoineLemaire
Copy link

I noticed on a link redirect link from Facebook where Neat Url did not clean it:

www.cuisineactuelle.fr/recettes/mini-burgers-au-foie-gras-331523#utm_source=Facebook&utm_medium=social&utm_campaign=PassionApero

It seams that's the # instead of ? which introduce this behavior

@Smile4ever
Copy link
Owner

I will look what I can do.

@kafene
Copy link

kafene commented Nov 23, 2017

I think I have a related issue

I encounted this url: https://vivaldi.com/blog/teamblog/vivaldi-1-13-adds-window-panel/#pk_campaign=newsletter&pk_kwd=community

I want to filter #pk_campaign and #pk_kwd

I see in the source code it does build a list of hashParams but only replaces the whole thing if it matches.

I came up with a simplistic implementation using a secondary URL object to track the hash as if it were a query string, which is an approach that many sites use.

(function () {
    const url = new URL('https://vivaldi.com/blog/teamblog/vivaldi-1-13-adds-window-panel/?removethis=true#pk_campaign=newsletter&pk_kwd=community');
    const fields = ['#pk_campaign', '#pk_kwd', 'removethis'];

    const hashUrl = new URL(url.href);
    hashUrl.search = hashUrl.hash.replace('#', '');
    hashUrl.hash = '';

    for (const field of fields) {
        if (field.startsWith('#')) {
            const fieldName = field.replace('#', '');
            hashUrl.searchParams.delete(fieldName);
        } else if (url.searchParams.has(field)) {
            url.searchParams.delete(field);
        }
    }

    const newHash = hashUrl.search.replace('?', '');
    url.hash = newHash ? `#${newHash}` : '';

    return url.href;
})();

// returns 'https://vivaldi.com/blog/teamblog/vivaldi-1-13-adds-window-panel/'

Perhaps this sort of replacement needs a special notation, like #&pk_campaign to indicate that it's both a hash string and the item is to be treated as a parameter within that string.

Anyways, thank you for your hard work with Neat URL!

@Smile4ever
Copy link
Owner

Thank you for your hard work. It is indeed a simplistic implementation but it shows the intent. Maybe I can use the code with some changes. Please be patient as this will take some time to adapt for Neat URL.

Smile4ever added a commit that referenced this issue Dec 1, 2017
* Performance improvements
* Several encoding bugs fixed #73 #75 #93
* Re-initialise listener, hopefully fixes #92
* Fix "Show counter" setting (introduced in 3.2.0) doesn't do anything #91
* Workaround for gws_rd@google.* on google.com #76
* Implement hash parameters using #? #83
* Cleanups
* Fix translation string mapped to wrong i18n id
* Move most functions related to the toolbar button to a separate file
@Smile4ever
Copy link
Owner

Implemented in Neat URL 4.0.0 which is now available on addons.mozilla.org.

@Geobert
Copy link

Geobert commented Dec 29, 2017

This is great!
Should update the documentation though: we still refer #xtor=RSS-8 as valid but it doesn't work anymore, I needed to change it to #?xtor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants