Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from schoenbergerb/not-def-glyph-fix
Browse files Browse the repository at this point in the history
Not def glyph fix
  • Loading branch information
schoenbergerb authored Dec 21, 2021
2 parents 2590853 + bf2f630 commit 80720fb
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"name": "Launch via NPM",
"request": "launch",
"runtimeArgs": [
"test"
"run",
"demo"
],
"runtimeExecutable": "npm",
"skipFiles": [
Expand Down
25 changes: 25 additions & 0 deletions example/demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import obfuscate from '../src'
import { EncryptionCharakterRange } from '../src/encryption-character-range.enum'
import fs from 'fs'

obfuscate(
{ data: "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!§$%&/()=?¬”#£fi^``-,.-M:;_,,;#+#+äölü"},
__dirname + "/example.ttf",
{ characterRange: EncryptionCharakterRange.KATAKANA }
).then(({value, font}) => {
fs.writeFileSync('./example.html', `
<html>
<head>
<style>
@font-face {
font-family: 'noscrape-obfuscated';
src: url('data:font/truetype;charset=utf-8;base64,${font.toString('base64')}');
}
</style>
</head>
<body style="font-family: 'noscrape-obfuscated'">
${value.data}
</body>
</html>
`)
})
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "@noscrape/noscrape",
"version": "0.1.6",
"version": "0.1.7",
"description": "protect your content from scraping",
"homepage": "https://noscrape-nexample.vercel.app",
"keywords": ["scraping", "noscrape", "crawler", "websecurity", "scrape", "obfuscation", "obfuscate", "defend", "protection"],
"main": "dist/index.js",
"scripts": {
"run": "ts-node main.ts",
"build": "tsc",
"test": "jest"
"test": "jest",
"demo": "ts-node example/demo.ts"
},
"author": "Bernhard Schönberger",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/encryption-character-range.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export enum EncryptionCharakterRange {
/* 0590 - 05FF Hebrew */
HEBREW = 1424,

/* E000 - F8FF Private Use Area */
DEFAULT = 57344,
/* E000 - F8FF Private Use Area - DEFAULT */
PRIVATE_USE_AREA = 57344,

/* 3040 - 309F Hiragana */
HIRAGANA = 12352,
Expand Down
3 changes: 2 additions & 1 deletion src/glyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function obfuscateGlyphs(
const translation = new Map<number, number>();

const startFromUnicode =
options?.characterRange ?? EncryptionCharakterRange.DEFAULT;
options?.characterRange ?? EncryptionCharakterRange.PRIVATE_USE_AREA;

const glyphs = originalGlyphs.map((glyph, index) => {
const unicode = index + startFromUnicode;
Expand Down Expand Up @@ -37,6 +37,7 @@ export default function obfuscateGlyphs(
commands,
},
advanceWidth: glyph.advanceWidth,
leftSideBearing: glyph.leftSideBearing,
});
});

Expand Down
8 changes: 7 additions & 1 deletion src/value2glyphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@ export default function value2glyphs<T>(value: T, font: Font): Glyph[] {

const uniqChars = _.union(chars);

return font.stringToGlyphs(_.shuffle(uniqChars).join(""));
const glyphs = font.stringToGlyphs(_.shuffle(uniqChars).join(""));

const notDefGlyph = font.glyphs.glyphs[0]

glyphs.unshift(notDefGlyph)

return glyphs
}

0 comments on commit 80720fb

Please sign in to comment.