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

What to input in URL matcher? #39

Closed
hartnn opened this issue Oct 4, 2016 · 11 comments
Closed

What to input in URL matcher? #39

hartnn opened this issue Oct 4, 2016 · 11 comments
Assignees
Milestone

Comments

@hartnn
Copy link

hartnn commented Oct 4, 2016

My aim is to automatically rename tabs using the URL.

For example: if the URL is cdetsng.company.com/blah/ABCde12345&xyz=1/... , then I want to tab tile to display only the variable part "de12345", because the part before that remains same (like for ABCef67890, the URL will be cdetsng.company.com/blah/ABCef67890). (I can easily put the title as ABC, but that's of no use to me.)

What should go in URL matcher to do this?
screen shot 2016-10-04 at 6 19 27 pm

@sylouuu
Copy link
Collaborator

sylouuu commented Oct 4, 2016

Hello @hartnn,

You have to put the write RegExp that will catch the need part of text. Maybe @denilsonsa may help you?

And just write $1 in the title input to display it.

Bests

@hartnn
Copy link
Author

hartnn commented Oct 4, 2016

Thanks for the prompt reply sylouuu!
While we wait for @denilsonsa to check this, I will mention what I tried here :
Title : $1
URL matcher : https\:\/\/cdetsng.company.com\/blah\/\#view\=ABC(.+?)[&\s\/]

doesn't work....
not even just ABC(.+?)[&\s\/]

@denilsonsa
Copy link
Contributor

First you wrote cdetsng.company.com/blah/ABCde12345&xyz=1/, but I believe you meant cdetsng.company.com/blah/#view=ABCde12345&xyz=1/.

I'd try: #view=ABC([^&#/]+)


It occurred to me that the URI is probably changing after the page load, and I don't think the extension supports it yet. @sylouuu try this:

  1. Add this rule:
    • URL contains developer.mozilla.org
    • Title: :$1
    • URL matcher: #(.*)
  2. Open: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Introduction
  3. Click on any of the links from the table of contents (the sidebar to the right). They change the hash portion of the URI, but the extension does not detect it.
  4. Try a different URI: https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/hash#Examples
  5. This time, the extension manages to change the title as expected, but the title will get out of date as soon as we repeat the step 3 on this page.

@sylouuu
Copy link
Collaborator

sylouuu commented Oct 4, 2016

Hey @denilsonsa,

Thanks for this answer. Waiting for @hartnn reply to know if your suggestion solves his issue.

By the way, you just pointed a bug. Actually, the overall process isn't applied when the hash changes, only on page load.

I should reprocess when this event is fired.

Bests

@hartnn
Copy link
Author

hartnn commented Oct 4, 2016

Yes! That works.

Worked for cdetsng.company.com/blah/#view=ABCde12345
and
cdetsng.company.com/blah/#view=ABCde12345&xyz=1
too.
Thanks, thats what I wanted 👍

Just one minor thing:
I do have links of different such URLs (again only the variable part "de12345"), in every such page.
Now if I am on page with tab title 'de12345' and click on link with variable part as 'ef67890', the tab title does not automatically change with URL, stays the same, unless refreshed.

Is this the same bug you both are talking about?
Though I am fine with that, it would be great if tab title automatically changes with URL without the need of refreshing page.

@sylouuu
Copy link
Collaborator

sylouuu commented Oct 4, 2016

Glad it's OK. Yes it's a bug I just noticed.

By the way, you just pointed a bug. Actually, the overall process isn't applied when the hash changes, only on page load.

I will plan this fix.

Bests

@denilsonsa
Copy link
Contributor

Worked for cdetsng.company.com/blah/#view=ABCde12345

That's why. You showed us one kind of URL, but were trying to match against a different kind.

ABC(.+?)[&\s\/] means:

  1. The letters ABC,
  2. Followed by any characters one or more times (non-greedy, and save this as a group),
  3. Followed by one of &, whitespace, /.

The part 3 of this regex can't match anything on that URL from the top of this comment, but works on the other URLs you showed in your earlier comments.

@sylouuu sylouuu added this to the 0.16.1 milestone Oct 5, 2016
@sylouuu
Copy link
Collaborator

sylouuu commented Oct 5, 2016

Just released 0.16.1. This will fix the window hash detection.

Bests

@sylouuu sylouuu closed this as completed Oct 5, 2016
@sylouuu
Copy link
Collaborator

sylouuu commented Oct 5, 2016

I think I have to revert this @hartnn @denilsonsa.

  1. Add this rule:
    • URL contains developer.mozilla.org
    • Title: test {title}
    • URL matcher: #(.*)
  2. Open: https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/hash#Examples
  3. Click on some links (hash)

The tab title is not as expected.

@sylouuu sylouuu reopened this Oct 5, 2016
@hartnn
Copy link
Author

hartnn commented Oct 5, 2016

The fix takes previous title and runs the rule again through processPage(),
hence we see test written many times.
Instead of taking previous title, can you save and take the first title that came after page load?
Maybe that can fix the issue we see....but you know better :)

PS : Your fix works fine for my set of web pages.

sylouuu added a commit that referenced this issue Oct 6, 2016
@sylouuu
Copy link
Collaborator

sylouuu commented Oct 6, 2016

Just reverted previous changes. Sorry.

I'll take a look later about that.

Bests

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

3 participants