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

(Github Image Viewer) regex pattern improvements + directory detection #82

Closed
jP6a9b3OR6FN5mVP81pQ2aOrtfMhKEhaBX8WkP1 opened this issue Nov 14, 2015 · 7 comments

Comments

@jP6a9b3OR6FN5mVP81pQ2aOrtfMhKEhaBX8WkP1

• with regexp: add .bmp format (e.g. https://github.com/quentinmrzt/Darlizot/tree/master/sprite), escape filetype dots and ignore the case (e.g. https://github.com/PeterLawrence/WinTimeStampUtility)

--- _imageRegex: /(.jpe?g|.png|.gif|.ico|.tiff?)$/,
+++ _imageRegex: /(\.jpe?g|\.png|\.gif|\.bmp|\.ico|\.tiff?)$/i,

• with folders: check icon sibling for '.octicon-file-text' / !'.octicon-file-directory' class (e.g. https://github.com/github/octicons)

if (target.classList && target.classList.contains("js-directory-link")
+++     && target.parentElement.parentElement.parentElement.firstElementChild.firstElementChild.classList.contains("octicon-file-text")
        && GithubImageViewer._imageRegex.test(target.href)) {
@jerone
Copy link
Owner

jerone commented Nov 14, 2015

@jP6a9b3OR6FN5mVP81pQ2aOrtfMhKEhaBX8WkP1 commented on 14 nov. 2015 05:30 CET:

• with regexp: add .bmp format (e.g. https://github.com/quentinmrzt/Darlizot/tree/master/sprite), escape filetype dots and ignore the case (e.g. https://github.com/PeterLawrence/WinTimeStampUtility)

--- _imageRegex: /(.jpe?g|.png|.gif|.ico|.tiff?)$/,
+++ _imageRegex: /(\.jpe?g|\.png|\.gif|\.bmp|\.ico|\.tiff?)$/i,

These changes are awesome! If you want credit you can send a PR. Otherwise I can make the changes if you want.

• with folders: check icon sibling for '.octicon-file-text' / !'.octicon-file-directory' class (e.g. https://github.com/github/octicons)

if (target.classList && target.classList.contains("js-directory-link")
+++     && target.parentElement.parentElement.parentElement.firstElementChild.firstElementChild.classList.contains("octicon-file-text")
        && GithubImageViewer._imageRegex.test(target.href)) {

You mean when folders are named after image extensions, including the dot?

@jP6a9b3OR6FN5mVP81pQ2aOrtfMhKEhaBX8WkP1

@jerone commented on [Nov 14, 2015, 12:54 PM GMT+2](https://github.com/jerone/UserScripts/
issues/82#issuecomment-156683879):

These changes are awesome! If you want credit you can send a PR. Otherwise I can make the changes if you want.

it will be very kind of you if you do everything by yourself

You mean when folders are named after image extensions, including the dot?

yes, exactly: prevent GithubImageViewer from triggering by folders with names like "bmp"/".bmp"

@jerone
Copy link
Owner

jerone commented Nov 14, 2015

@jP6a9b3OR6FN5mVP81pQ2aOrtfMhKEhaBX8WkP1 commented on 14 nov. 2015 13:19 CET:

@jerone commented on [Nov 14, 2015, 12:54 PM GMT+2](https://github.com/jerone/UserScripts/
issues/82#issuecomment-156683879):

You mean when folders are named after image extensions, including the dot?

yes, exactly: prevent GithubImageViewer from triggering by folders with names like "bmp"/".bmp"

I want to stay away from GitHub page elements as much as possible, definitely traveling up the tree and back down again. They change their page layout very often. I was thinking of extending the regex:

--- _imageRegex: /(\.jpe?g|\.png|\.gif|\.bmp|\.ico|\.tiff?)$/i,
+++ _imageRegex: /.+(\.jpe?g|\.png|\.gif|\.bmp|\.ico|\.tiff?)$/i,

@jP6a9b3OR6FN5mVP81pQ2aOrtfMhKEhaBX8WkP1

I want to stay away from GitHub page elements as much as possible ...

agree with such intentions, but unfortunately there no other way in code

... definitely traveling up the tree and back down again ...

3 ups to ".js-navigation-item" and ~ queryselector/queryselectorall[0] ".js-navigation-item .octicon-file-text" )

... They change their page layout very often. ...

once or twice per year during last few years or am I wrong? knocking on wood

I was thinking of extending the regex:

--- _imageRegex: /(\.jpe?g|\.png|\.gif|\.bmp|\.ico|\.tiff?)$/i
+++ _imageRegex: /.+(\.jpe?g|\.png|\.gif|\.bmp|\.ico|\.tiff?)$/i

ok, but it just simply excludes ".bmp"-named file or folder

@jerone
Copy link
Owner

jerone commented Nov 14, 2015

@jP6a9b3OR6FN5mVP81pQ2aOrtfMhKEhaBX8WkP1 commented on 14 nov. 2015 15:01 CET:

I was thinking of extending the regex:

--- _imageRegex: /(\.jpe?g|\.png|\.gif|\.bmp|\.ico|\.tiff?)$/i
+++ _imageRegex: /.+(\.jpe?g|\.png|\.gif|\.bmp|\.ico|\.tiff?)$/i

ok, but it just simply excludes ".bmp"-named file or folder

Anything named X.bmp for example. I can understand someone naming a folder bmp or .bmp, but a folder named anything.bmp seems far fetched.
I'm going to use the new regex, I can always change to DOM traversing when more examples pop-up. Thanks for the improvements!

jerone added a commit that referenced this issue Nov 14, 2015
@jerone jerone closed this as completed in 2bad37e Nov 14, 2015
@jerone
Copy link
Owner

jerone commented Nov 14, 2015

🎬 Released new version of Github Image Viewer

@jerone jerone removed their assignment Nov 14, 2015
@jP6a9b3OR6FN5mVP81pQ2aOrtfMhKEhaBX8WkP1

the same to you

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

2 participants