Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Homepage #33

Merged
merged 45 commits into from
Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8e933f7
Add Competitive_Gwent
Soreine Aug 5, 2017
6bf9b32
Refactor tooltip code
Soreine Aug 5, 2017
3078b52
Following mouse
Soreine Aug 5, 2017
af94df6
Keep card within viewport
Soreine Aug 5, 2017
f7a24cf
Added aliases
Soreine Aug 5, 2017
2cbb61c
Add failing test for accentuated letters
Soreine Aug 5, 2017
68e9781
Add back accents
Soreine Aug 5, 2017
ae0ba8d
Support accents
Soreine Aug 5, 2017
e19eb43
Fix error in Chrome
Soreine Aug 5, 2017
f8933fc
Merge branch 'follow-mouse' into aliases
Soreine Aug 5, 2017
25d5b55
Support GwentDB (don't double tooltips)
Soreine Aug 6, 2017
2798cb3
Cleanup
Soreine Aug 6, 2017
9cdf17f
Wrote content for home page
Soreine Aug 6, 2017
f8699e1
Wrote content for home page
Soreine Aug 6, 2017
f4e3c71
Merge branch 'support-gwentdb' into homepage
Soreine Aug 6, 2017
e59f79e
Merge branch 'aliases' into homepage
Soreine Aug 6, 2017
a1ca3bf
Add frog and fix ADC
Soreine Aug 6, 2017
466427c
Hyper Gwent logo using Sketch
Soreine Aug 6, 2017
4f26338
Improve R
Soreine Aug 6, 2017
a4ab406
Fix kerning
Soreine Aug 6, 2017
d1231d3
Add colors :rainbow:
Soreine Aug 6, 2017
f0a09a9
Improving homepage style
Soreine Aug 6, 2017
5456322
Add dandelion and geralt avatars
Soreine Aug 6, 2017
e7ff027
Fix walker to skip script and styles tags
Soreine Aug 6, 2017
07e6bc8
Added emotes :p
Soreine Aug 6, 2017
7c80984
Fix responsiveness
Soreine Aug 6, 2017
e0501b3
Another wordplay
Soreine Aug 6, 2017
6d2f303
Dark theme
Soreine Aug 6, 2017
921c61e
Grammar
Soreine Aug 6, 2017
f259b20
Add link to issues
Soreine Aug 6, 2017
7e6c5c7
Style issues
Soreine Aug 6, 2017
8d6c37f
Add gradient background
Soreine Aug 6, 2017
3613bbe
Link to compose a message
Soreine Aug 6, 2017
13904ee
Add favicon
Soreine Aug 6, 2017
cbcab1a
Remove border from logo
Soreine Aug 6, 2017
6db7f90
Add back border, but better
Soreine Aug 6, 2017
fb7e87e
Adjust button colors
Soreine Aug 6, 2017
1b89bef
Add warning for non Chrome users. Fix rem
Soreine Aug 6, 2017
b65a950
Fix rem
Soreine Aug 6, 2017
70e3bb6
Remove list style
Soreine Aug 6, 2017
0984e2a
Update manifest.json
Soreine Aug 6, 2017
892b387
Limit extension to GwentDB decks
Soreine Aug 6, 2017
df54ea9
Fix manifest.json
Soreine Aug 6, 2017
b750b8e
Extend to GwentDB forums
Soreine Aug 6, 2017
0ef638c
Merge branch 'master' into homepage
Soreine Aug 7, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added favicon.ico
Binary file not shown.
Binary file added favicon128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added favicon16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added favicon32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added favicon40x40.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added favicon48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hyper-gwent.sketch
Binary file not shown.
Binary file removed icon128.png
Binary file not shown.
Binary file removed icon16.png
Binary file not shown.
Binary file removed icon40.png
Binary file not shown.
Binary file removed icon48.png
Binary file not shown.
15 changes: 9 additions & 6 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
{
"manifest_version": 2,
"author": "Soreine & Zhouzi",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

"homepage": "https://soreine.github.io/hyper-gwent",
"name": "Hyper Gwent",
"description": "Enrich pages containing GwentⓇ related content. Card names quick access, terms highlight and more!",
"description": "Show tooltips for cards in pages containing GwentⓇ related content.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that's an issue but this description is different than the one on the website.

"version": "0.1.0",
"manifest_version": 2,
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
"16": "favicon16x16.png",
"48": "favicon48x48.png",
"128": "favicon128x128.png"
},
"content_scripts": [
{
"matches": [
"https://www.reddit.com/r/gwent/*",
"https://www.reddit.com/r/Competitive_Gwent/*",
"http://www.gwentdb.com/*"
"http://www.gwentdb.com/decks/*",
"http://www.gwentdb.com/forums/*"
],
"js": [
"dist/content.js"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"gwent-api-client": "^1.1.0",
"html-webpack-plugin": "^2.29.0",
"style-loader": "^0.16.1",
"svg-inline-loader": "^0.8.0",
"url-loader": "^0.5.9",
"webpack": "^3.0.0"
}
Expand Down
7 changes: 6 additions & 1 deletion src/core/__tests__/findAllMatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ test('Should detect plurals', (t) => {
});

test('Should detect aliases', (t) => {
const text = 'Frost, Yen, YenCon, QG and light cavalries';
const text = 'Frost, Yen, YenCon, QG and light cavalries and ADC';
const matchedRanges = findAllMatches(DICTIONARY, text);
t.deepEqual(matchedRanges, [
{
Expand Down Expand Up @@ -179,6 +179,11 @@ test('Should detect aliases', (t) => {
entryValue: 'Dun Banner Light Cavalry',
start: 27,
end: 42,
}, {
entryKey: 'adc',
entryValue: "Alzur's Double–Cross",
start: 47,
end: 50,
},
]);
});
Expand Down
4 changes: 2 additions & 2 deletions src/core/data/ALIASES.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ALIASES = {
],
Albrich: [],
Alchemist: [],
"Alzur's Double Cross": [
"Alzur's DoubleCross": [
'adc',
],
"Alzur's Thunder": [
Expand Down Expand Up @@ -299,7 +299,7 @@ const ALIASES = {
Ghoul: [],
'Giant Toad': [
'toad',
// 'frog',
'frog',
],
'Grave Hag': [
// 'gh',
Expand Down
82 changes: 2 additions & 80 deletions src/extension/content.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,3 @@
/* global window, document */
import walk from './walk';

import urlParse from 'url-parse';
import findAllMatches from '../core/findAllMatches';
import replaceMatches from '../core/replaceMatches';
import tooltip from '../core/tooltip/index';
import { CARDS } from '../core/data';
import DICTIONARY from '../core/dictionary';

const CLASSNAME = 'hyper-gwent-card-highlight';
const CARD_NAME_ATTRIBUTE = 'data-card-name';
const GWENTDB_TOOLTIP_ATTR = 'data-tooltip-url';
const GWENTDB_HOSTNAME = 'www.gwentdb.com';

const HOSTNAME = urlParse(window.location.href).hostname;

const walker = window.document.createTreeWalker(
window.document.body,
window.NodeFilter.SHOW_ELEMENT + window.NodeFilter.SHOW_TEXT,
// Filter out GwentDB tooltips
{
acceptNode(node) {
const TEXT_NODE = 3;
const ELEMENT_NODE = 1;

const {
FILTER_ACCEPT,
FILTER_REJECT,
FILTER_SKIP,
} = window.NodeFilter;

// Non GwentDB
if (HOSTNAME !== GWENTDB_HOSTNAME) {
return node.nodeType === TEXT_NODE
? FILTER_ACCEPT
: FILTER_SKIP;
}

// on GwentDB, we skip existing tooltips
if (
node.nodeType === ELEMENT_NODE
&& node.getAttribute(GWENTDB_TOOLTIP_ATTR)
) {
// Skip this node and all its children
return FILTER_REJECT;
} else if (node.nodeType === TEXT_NODE) {
return FILTER_ACCEPT;
}
return FILTER_SKIP;
},
},
);
const nodes = [];

while (walker.nextNode()) {
const node = walker.currentNode;
const matches = findAllMatches(DICTIONARY, node.nodeValue);

if (matches.length) {
nodes.push({
node,
matches,
});
}
}

nodes.forEach(({ node, matches }) => {
const span = window.document.createElement('span');
span.innerHTML = replaceMatches(node.nodeValue, matches, match => `<span class="${CLASSNAME}" ${CARD_NAME_ATTRIBUTE}="${match.entryValue}" style="border-bottom: 1px dashed; padding-bottom: 0.1em">${node.nodeValue.slice(match.start, match.end)}</span>`);

node.parentNode.replaceChild(span, node);
});

// Add tooltips
const highlights = document.getElementsByClassName(CLASSNAME);
for (let i = 0; i < highlights.length; i += 1) {
const highlight = highlights[i];
const cardName = highlight.getAttribute(CARD_NAME_ATTRIBUTE);
const card = CARDS[cardName];
tooltip(card, highlight);
}
walk();
91 changes: 91 additions & 0 deletions src/extension/walk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* global window, document */

import urlParse from 'url-parse';
import findAllMatches from '../core/findAllMatches';
import replaceMatches from '../core/replaceMatches';
import tooltip from '../core/tooltip/index';
import { CARDS } from '../core/data';
import DICTIONARY from '../core/dictionary';

const CLASSNAME = 'hyper-gwent-card-highlight';
const CARD_NAME_ATTRIBUTE = 'data-card-name';
const GWENTDB_TOOLTIP_ATTR = 'data-tooltip-url';
const GWENTDB_HOSTNAME = 'www.gwentdb.com';

// Walk the document and highlight cards
function walk() {
const HOSTNAME = urlParse(window.location.href).hostname;

const walker = window.document.createTreeWalker(
window.document.body,
window.NodeFilter.SHOW_ELEMENT + window.NodeFilter.SHOW_TEXT,
// Filter out GwentDB tooltips
{
acceptNode(node) {
const TEXT_NODE = 3;
const ELEMENT_NODE = 1;

const {
FILTER_ACCEPT,
FILTER_REJECT,
FILTER_SKIP,
} = window.NodeFilter;

if (node.nodeType === TEXT_NODE) {
return FILTER_ACCEPT;
} else if (
node.nodeType === ELEMENT_NODE
) {
// Ignore style and scripts
if (node.tagName === 'STYLE'
|| node.tagName === 'SCRIPT') {
return FILTER_REJECT;
}

// on GwentDB, we skip existing tooltips
if (HOSTNAME === GWENTDB_HOSTNAME
&& node.getAttribute(GWENTDB_TOOLTIP_ATTR)) {
// Skip this node and all its children
return FILTER_REJECT;
}

// Skip the node itself
return FILTER_SKIP;
}
return FILTER_SKIP;
},
},
);

const nodes = [];

while (walker.nextNode()) {
const node = walker.currentNode;
const matches = findAllMatches(DICTIONARY, node.nodeValue);

if (matches.length) {
nodes.push({
node,
matches,
});
}
}

nodes.forEach(({ node, matches }) => {
const span = window.document.createElement('span');
span.innerHTML = replaceMatches(node.nodeValue, matches, match => `<span class="${CLASSNAME}" ${CARD_NAME_ATTRIBUTE}="${match.entryValue}" style="border-bottom: 1px dashed; padding-bottom: 0.1em">${node.nodeValue.slice(match.start, match.end)}</span>`);

node.parentNode.replaceChild(span, node);
});

// Add tooltips
const highlights = document.getElementsByClassName(CLASSNAME);
for (let i = 0; i < highlights.length; i += 1) {
const highlight = highlights[i];
const cardName = highlight.getAttribute(CARD_NAME_ATTRIBUTE);
const card = CARDS[cardName];
tooltip(card, highlight);
}
}

export default walk;
Binary file added src/website/dandelion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/website/geralt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
110 changes: 87 additions & 23 deletions src/website/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,95 @@

// eslint-disable-next-line no-unused-vars
import { createElement } from 'jsx-dom';
import tooltip from '../core/tooltip/index';
import walk from '../extension/walk';
import Logo from './logo.svg';
import style from './website.css';

const target = <span id="target" style="color: blue;">Aeromancy</span>;
const app = (
const REDDIT = 'https://www.reddit.com/r/gwent/';
const GWENTDB = 'http://www.gwentdb.com/';
const REPO = 'https://github.com/Soreine/hyper-gwent/issues';
const EXT_LINK = '#';

const notUsingChrome = !window.chrome;

const htmlPage = (
/* eslint-disable max-len */
<div>
<p>C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg.</p>
<p>Any fool can write code that a computer can understand. Good programmers write code that humans can understand.</p>
<p>This paragraph contains a card named {target}.</p>
<p>It's not a bug - it's an undocumented feature.</p>
<p>A good programmer is someone who always looks both ways before crossing a one-way street.</p>
<p>The perfect project plan is possible if one first documents a list of all the unknowns.</p>
<div className="content">
<style type="text/css">{style.toString()}</style>

<div className="logo">
<div className="logo-title"
innerHTML={Logo} />
<div className="logo-subtitle">{'Chrome extension for GWENT®: The Witcher Card Game'}</div>
</div>

<a className="download-link" href={EXT_LINK}>{'Add to Chrome'}</a>

{notUsingChrome && <p className="nochrome">
This extension is only available for Chrome. The demonstration on this page will not work in other browsers.
</p>}

<div className="description">
<p>
{'None of us can reasonably remember every possible Gwent card\'s name and effect. Browsing '}
<a href={REDDIT}>{'/r/gwent'}</a>
{' and reading deck guides on '}
<a href={GWENTDB}>{'GwentDB'}</a>
{' can be challenging if you don\'t know half the cards people are talking about.'}
</p>

<p>
<em>{'You might find this shocking:'}</em>
<ul>
<li>{'Xmen are not what they used to be.'}</li>
<li>{'ADC does not stand for Attack Damage Carry.'}</li>
<li>{'There '}<em>{'are'}</em>{' worst names for a dragon than Borkh.'}</li>
<li>{'Gwent has nothing to do with cooking frogs, mushrooms, or anything remotely related to french cuisine.'}</li>
</ul>
</p>

<div className="emote">
<div className="avatar geralt"></div>
<div className="emote-text">
{'Not bad. Not bad at all.'}
</div>
</div>

<p>
{'Whether you are new to the game, or you want to keep up with the latest card changes, or you can\'t remember crap, Hyper Gwent is here to save the day. Hyper Gwent automatically detects card names or acronyms in the pages you visit, highlights them and shows a tooltip when hovering them.'}
</p>

<p>
{'Feature list:'}
<ul>
<li>{'Up to date with all existing cards'}</li>
<li>{'Support acronyms, plurals, lowercase, and missing accents'}</li>
<li>{'Lightweight'}</li>
</ul>
</p>

<p>{'What do you think of that, Dandelion?'}</p>

<div className="emote">
<div className="avatar dandelion"></div>
<div className="emote-text">
{'That… was actually rather impressive. Congratulations.'}
</div>
</div>

</div>

<a className="download-link" href={EXT_LINK}>{'Add to Chrome'}</a>

<p className="issues">
If you find bugs, if you want to submit new acronyms, request a feature, or contribute, post an issue <a href={REPO}>here</a>.
<br/>
You can also contact <a href="https://www.reddit.com/message/compose/?to=Soreine">/u/Soreine</a>.</p>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could customize the HTML template to include all this, it'd be better for SEO & all. The Webpack loader would just insert the JavaScript specific code.

</div>
/* eslint-enable max-len */
);
window.document.body.appendChild(app);

tooltip({
name: 'Aeromancy',
info: 'Play a Bronze or Silver Weather card from your Deck or Graveyard. Shuffle the others from your Deck back.',
variations: [
{
art: {
thumbnailImage: 'https://api.gwentapi.com/media/aeromancy-thumbnail.png',
},
},
],
}, target);
window.document.body.appendChild(htmlPage);


// Launch extension within the page
walk();
Loading