Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from perry-mitchell/refactor
Refactor
- Loading branch information
Showing
27 changed files
with
3,558 additions
and
595 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[{package.json,package-lock.json}] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
integration: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Integration tests ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm ci | ||
- run: npm run test:integration | ||
# formatting: | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - uses: actions/checkout@v2 | ||
# - name: Formatting | ||
# uses: actions/setup-node@v1 | ||
# with: | ||
# node-version: 20.x | ||
# - run: npm ci | ||
# - run: npm run test:format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,3 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | ||
node_modules | ||
/dist |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"typescript.preferences.importModuleSpecifierEnding": "js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# SlyFox Changelog | ||
|
||
## v1.0.0 | ||
_2023-12-02_ | ||
|
||
* First major release | ||
* Renamed from `archetype` to `slyfox` | ||
* ESM | ||
* Typescript |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,4 @@ | ||
# archetype | ||
Restore overwritten methods on the window. | ||
# SlyFox | ||
> Restore overwritten methods on the window and document... **Like a fox**. | ||
[![Build Status](https://travis-ci.org/perry-mitchell/archetype.svg)](https://travis-ci.org/perry-mitchell/archetype) [![archetype is on Bower](https://badge.fury.io/bo/archetype.svg)](https://github.com/perry-mitchell/archetype) | ||
|
||
## Making repairs | ||
Libraries like Prototype.js do immeasureable harm to the shared environments that are webpages. 3rd party libraries - like those used in tracking and advertising scripts - must ensure that they can cope with whatever broken system is presented to them. Libraries like Prototype assume that what they add is for the benefit of the developer and that single website, and that the extensions they provide won't harm existing functionality - but that's obviously incorrect, and Archetype is here to fix those problems in a simple manner. | ||
|
||
### What it does | ||
Archetype provides access to original window methods that may have been overwritten by some script. | ||
|
||
### How it does it | ||
The library uses an iframe to create a clean environment in which to extract methods from. When a function is requested from archetype, the main window is checked for a native function - if that function is not native, a native version will be taken from within an iframe, bound to the top-level and returned. | ||
|
||
## API | ||
**NB:** archetype is loaded asynchronously, due to the fact that it requires `document.body.appendChild` to be defined for inserting its safe-iframe. Before using archetype, wrap your code in the following: | ||
|
||
```javascript | ||
archetype.onReady(function() { | ||
|
||
var getElementById = archetype.getNativeMethod("document.getElementById"); | ||
|
||
}); | ||
``` | ||
|
||
### getNativeMethod(path{, bindContext}) | ||
Fetches a native window method at a given path. A path is simply the string representation of a method's location on the window: eg. window.setInterval. `bindContext` is an optional object to bind at the context - if not provided, the window/document will be used instead. | ||
|
||
If a method like `window.document.querySelector` is overwritten by some crappy JavaScript, you can retrieve it by calling `var querySelector = archetype.getNativeMethod("window.document.querySelector");`. | ||
|
||
In the same way, if you would like to make sure an HTML element has the native function you can call `var qsEl = archetype.getNativeMethod("window.document.querySelector", divElement);` | ||
|
||
### isNative(pathOrMethod) | ||
Checks if a method is native (not overwritten). You can pass a path (eg. "window.setTimeout") or an actual function. | ||
|
||
### patchMethod(path) | ||
Patches a method on the top window. This function checks to see if the method on the top window is native or not, and if it **isn't**, it is overwritten with a native copy from the _safe_ window from a clean iframe. | ||
|
||
## Use-cases | ||
|
||
### Fixing overwritten query selectors | ||
Some libraries like Prototype.js and CloudFlare's RocketLoader overwrite methods like `querySelector` and `querySelectorAll`, which is a very stupid idea. Fixing this is simple: | ||
|
||
```javascript | ||
["document.querySelector", "document.querySelectorAll"].forEach(archetype.patchMethod); | ||
``` | ||
|
||
This approach is somewhat fighting fire with fire, so the better option would be to simply keep a reference to a valid selector method: | ||
|
||
```javascript | ||
var querySelector = archetype.getNativeMethod("document.querySelector"), | ||
querySelectorAll = archetype.getNativeMethod("document.querySelectorAll"); | ||
``` | ||
_TBA_. |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.