-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
17 changed files
with
268 additions
and
158 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
/** | ||
* Interactive behavior for duplicate reports. | ||
*/ | ||
|
||
import { assertNotNull } from './utils/assert'; | ||
import { $, $$ } from './utils/dom'; | ||
|
||
export function setupDupeReports() { | ||
const onion = $<SVGSVGElement>('.onion-skin__image'); | ||
const slider = $<HTMLInputElement>('.onion-skin__slider'); | ||
const swipe = $<SVGSVGElement>('.swipe__image'); | ||
|
||
if (swipe) setupSwipe(swipe); | ||
if (onion && slider) setupOnionSkin(onion, slider); | ||
} | ||
|
||
function setupSwipe(swipe: SVGSVGElement) { | ||
const [ clip, divider ] = $$<SVGRectElement>('#clip rect, #divider', swipe); | ||
const { width } = swipe.viewBox.baseVal; | ||
|
||
function moveDivider({ clientX }: MouseEvent) { | ||
// Move center to cursor | ||
const rect = swipe.getBoundingClientRect(); | ||
const newX = (clientX - rect.left) * (width / rect.width); | ||
|
||
divider.setAttribute('x', newX.toString()); | ||
clip.setAttribute('width', newX.toString()); | ||
} | ||
|
||
swipe.addEventListener('mousemove', moveDivider); | ||
} | ||
|
||
function setupOnionSkin(onion: SVGSVGElement, slider: HTMLInputElement) { | ||
const target = assertNotNull($<SVGImageElement>('#target', onion)); | ||
|
||
function setOpacity() { | ||
target.setAttribute('opacity', slider.value); | ||
} | ||
|
||
setOpacity(); | ||
slider.addEventListener('input', setOpacity); | ||
} |
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,74 @@ | ||
/** | ||
* Keyboard shortcuts | ||
*/ | ||
|
||
import { $ } from './utils/dom'; | ||
|
||
interface ShortcutKeycodes { | ||
[key: string]: () => void | ||
} | ||
|
||
function getHover(): string | null { | ||
const thumbBoxHover = $<HTMLDivElement>('.media-box:hover'); | ||
|
||
return thumbBoxHover && (thumbBoxHover.dataset.imageId || null); | ||
} | ||
|
||
function openFullView() { | ||
const imageHover = $<HTMLDivElement>('[data-uris]:hover'); | ||
|
||
if (!imageHover || !imageHover.dataset.uris) return; | ||
|
||
window.location = JSON.parse(imageHover.dataset.uris).full; | ||
} | ||
|
||
function openFullViewNewTab() { | ||
const imageHover = $<HTMLDivElement>('[data-uris]:hover'); | ||
|
||
if (!imageHover || !imageHover.dataset.uris) return; | ||
|
||
window.open(JSON.parse(imageHover.dataset.uris).full); | ||
} | ||
|
||
function click(selector: string) { | ||
const el = $<HTMLElement>(selector); | ||
|
||
if (el) { | ||
el.click(); | ||
} | ||
} | ||
|
||
function isOK(event: KeyboardEvent): boolean { | ||
return !event.altKey && !event.ctrlKey && !event.metaKey && | ||
document.activeElement !== null && | ||
document.activeElement.tagName !== 'INPUT' && | ||
document.activeElement.tagName !== 'TEXTAREA'; | ||
} | ||
|
||
const keyCodes: ShortcutKeycodes = { | ||
KeyJ() { click('.js-prev'); }, // J - go to previous image | ||
KeyI() { click('.js-up'); }, // I - go to index page | ||
KeyK() { click('.js-next'); }, // K - go to next image | ||
KeyR() { click('.js-rand'); }, // R - go to random image | ||
KeyS() { click('.js-source-link'); }, // S - go to image source | ||
KeyL() { click('.js-tag-sauce-toggle'); }, // L - edit tags | ||
KeyO() { openFullView(); }, // O - open original | ||
KeyV() { openFullViewNewTab(); }, // V - open original in a new tab | ||
KeyF() { // F - favourite image | ||
getHover() ? click(`a.interaction--fave[data-image-id="${getHover()}"]`) | ||
: click('.block__header a.interaction--fave'); | ||
}, | ||
KeyU() { // U - upvote image | ||
getHover() ? click(`a.interaction--upvote[data-image-id="${getHover()}"]`) | ||
: click('.block__header a.interaction--upvote'); | ||
}, | ||
}; | ||
|
||
export function listenForKeys() { | ||
document.addEventListener('keydown', (event: KeyboardEvent) => { | ||
if (isOK(event) && keyCodes[event.code]) { | ||
keyCodes[event.code](); | ||
event.preventDefault(); | ||
} | ||
}); | ||
} |
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,13 @@ | ||
/** | ||
* StaffHider | ||
* | ||
* Hide staff elements if enabled in the settings. | ||
*/ | ||
|
||
import { $$, hideEl } from './utils/dom'; | ||
|
||
export function hideStaffTools() { | ||
if (window.booru.hideStaffTools === 'true') { | ||
$$<HTMLElement>('.js-staff-action').forEach(el => hideEl(el)); | ||
} | ||
} |
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
Oops, something went wrong.