homerchen19 / github-file-icons

🌈 🗂 A browser extension which gives different filetypes different icons to GitHub, GitLab, gitea and gogs.
https://chrome.google.com/webstore/detail/file-icon-for-github-and/ficfmibkjjnpogdcfhfokmihanoldbfe
MIT License
1.46k stars 70 forks source link

Add support for self-hosted GitHub and GitLab environments #60

Closed fregante closed 5 years ago

fregante commented 5 years ago

Closes https://github.com/xxhomey19/github-file-icon/issues/2 Closes https://github.com/xxhomey19/github-file-icon/issues/55

Implemented like in Refined GitHub.

I skipped the tests because:

  1. They seem to also test what's already being taken care by these new modules
  2. Jest is failing on this, even though babel seems to be already configured:

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    /Users/bfred/Web/Gitbase/github-file-icon/node_modules/webext-dynamic-content-scripts/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import 'content-scripts-register-polyfill';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token import

    > 1 | import 'webext-dynamic-content-scripts';
        | ^
      2 | import addDomainPermissionToggle from 'webext-domain-permission-toggle';
homerchen19 commented 5 years ago

@fregante Thanks for the help!

But I got this warning when I loaded the extension in my Chrome. Screen Shot 2019-08-08 at 10 54 22

It's from here: https://github.com/fregante/webext-dynamic-content-scripts/blob/1fa71872232886a92d2743a63a832de9e01ff72b/index.ts#L18 Do you have any idea how to solve this?

homerchen19 commented 5 years ago

Also I think we could put

"optional_permissions": [
    "http://*/*",
    "https://*/*"
],

into manifest.json, which is the same as refined-github.

fregante commented 5 years ago

Oops! I need to change that. But also I suggest to use webextensions-polyfill at some point. Promised APIs are great

fregante commented 5 years ago

Fixed both points

homerchen19 commented 5 years ago

Thanks! But there are two issues I found

  1. The error ReferenceError: browser is not defined still occurs when running into this line. https://github.com/fregante/webext-dynamic-content-scripts/blob/master/index.ts#L23
  2. The option webNavigation can't be removed because Bitbucket seems to use history.pushState() to navigate, so content script can't be triggered without listening for onHistoryStateUpdated.
fregante commented 5 years ago

Line 28 doesn't appear in the final file, it's just TypeScript information Line 23: I had tried the script but I didn't see that issue. 😅

  1. I just published 6.0.3-0, can you install it with npm i webext-dynamic-content-scripts@next?

  2. You don't need webNavigation but something like pjax:end on GitHub, you don't want to inject the whole script every time the page changes. I don't know the exact event BitBucket fires but there's a very generic popstate you can listen to in content.js, without extra permissions.

homerchen19 commented 5 years ago
  1. Ah the version of webext-dynamic-content-scripts in package.json isn't updated. Could you update it?
  2. Ok then removed it. I'll check it out later.