This repository has been archived by the owner on Aug 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Competitive_Gwent * Refactor tooltip code * Following mouse * Keep card within viewport * Added aliases * Add failing test for accentuated letters * Add back accents * Support accents * Fix error in Chrome See tyxla/remove-accents#11 * Support GwentDB (don't double tooltips) * Cleanup * Wrote content for home page * Wrote content for home page * Add frog and fix ADC * Hyper Gwent logo using Sketch * Improve R * Fix kerning * Add colors 🌈 * Improving homepage style * Add dandelion and geralt avatars * Fix walker to skip script and styles tags * Added emotes :p * Fix responsiveness * Another wordplay * Dark theme * Grammar * Add link to issues * Style issues * Add gradient background * Link to compose a message * Add favicon * Remove border from logo * Add back border, but better * Adjust button colors * Add warning for non Chrome users. Fix rem * Fix rem * Remove list style * Update manifest.json * Limit extension to GwentDB decks * Fix manifest.json * Extend to GwentDB forums
- Loading branch information
Showing
25 changed files
with
363 additions
and
113 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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
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
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
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,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(); |
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,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; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.