GithubHelp home page GithubHelp logo

pd4d10 / console-importer Goto Github PK

View Code? Open in Web Editor NEW
831.0 831.0 57.0 2.97 MB

Easily import JS and CSS resources from Chrome console.

Home Page: https://chrome.google.com/webstore/detail/console-importer/hgajpakhafplebkdljleajgbpdmplhie

License: MIT License

HTML 10.01% TypeScript 89.99%
browser-extension chrome-extension console css javascript resources

console-importer's Introduction

Hi there 👋

console-importer's People

Contributors

francecil avatar hubingkang avatar pd4d10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

console-importer's Issues

Don't pollute the global namespace

Right now when using $i it puts the result (when finished) on the global namespace - the window.

I'm proposing that instead it returns a promise (due to the async nature of import) that evaluates with the result of executing the desired imported module.

Something like this

$i('lodash').then(_ => _.toNumber(null));

This could also be used with top-level await like this

const _ = await $i('lodash');
_.toNumber(null);

This is gives you the control whether or not you want to pollute the global namespace and how.
Plus, now you don't have to know how the internal module exposes itself ($, _, etc.)

Bug Report | `Faker` library path is outdated.

Hi, i love this library!
I'm happy to report a bug 😄
I found that Faker library path is outdated.

Minimal reproduction code

  1. run $i('Faker')
  2. see the download path of logs.

スクリーンショット 2022-08-23 23 24 22

console importer installs Faker v3.1.0 (https://cdnjs.cloudflare.com/ajax/libs/Faker/3.1.0/faker.min.js).
But latest Faker version is 7.4.0 (https://github.com/faker-js/faker/releases)

I'm afraid if you know, Faker repository has been replaced from Marak to Fakejs Community.
details below.
https://fakerjs.dev/about/announcements/2022-01-14.html#i-heard-something-happened-what-s-the-tldr

I'm looking forward to fixing it 👍

provide a console-importer gif show

2023-12-28 18 58 57

$i('axios');
$i('crypto-js');

axios.get('https://placekitten.com/200/300', { responseType: 'arraybuffer' })
  .then((response) => {
    // Convert the ArrayBuffer to WordArray
    const wordArray = CryptoJS.lib.WordArray.create(response.data);
    // Convert the WordArray to a base64 string
    const base64String = CryptoJS.enc.Base64.stringify(wordArray);
    const imageUrl = `data:image/jpeg;base64,${base64String}`; // Assuming the image is a JPEG
    // Create a new image and assign the base64 string as the source
    const image = new Image();
    image.onload = function() {
      // Once the image is loaded, use its dimensions to set the console padding
      const style = [
        'font-size: 1px;',
        `padding: ${this.naturalHeight / 2}px ${this.naturalWidth / 2}px;`, // Divide by 2 because of the 1px font-size trick
        `background: url(${imageUrl}) no-repeat;`,
        'background-size: contain;'
      ].join(' ');
      console.log('%c ', style);
    };
    image.src = imageUrl;
  })
  .catch((error) => {
    console.error('Error fetching or encoding the image:', error);
  });

from https://github.com/zhaoolee/ChromeAppHeroes/blob/master/page/121-console-importer-2023-12-20.md

script-src-elem

Refused to load the script 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval' *.xitu.io *.juejin.im *.baidu.com *.google-analytics.com *.meiqia.com dn-growing.qbox.me *.growingio.com *.guard.qcloud.com *.gtimg.com". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

CSP 网站安全策略 load 资源失败

对于有的网站 是有CSP安全策略的,这时候加载外部资料是有限制的,加载不成功的

比如 github 网站
image

可以想想办法,规避这个限制

‘$i('jquery')’ is success,but ‘$i('axios')‘ is failure

$i('jquery') is success

$i('jquery')
importer.js:2 [$i]: Searching for jquery, please be patient...
undefined
importer.js:2 [$i]: jquery is loading, please be patient...
importer.js:2 [$i]: jquery(https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js) is loaded.

$i('axios') is failure

$i('axios')
importer.js:2 [$i]: Searching for axios, please be patient...
undefined
7098146254491746334:1
Access to fetch at 'https://api.cdnjs.com/libraries?search=axios' from origin 'https://juejin.cn' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
monitors.3.6.34.cn.js:1

GET https://api.cdnjs.com/libraries?search=axios net::ERR_FAILED 502
importer.js:2 [$i]: There appears to be some trouble with your network. If you think this is a bug, please report an issue:
importer.js:2 [$i]: https://github.com/pd4d10/console-importer/issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.