-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into vanilla-video-safari
- Loading branch information
Showing
36 changed files
with
221 additions
and
354 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"root": true, | ||
"env": { | ||
"browser": true, | ||
"es2021": true, | ||
|
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 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,5 @@ | ||
{ | ||
"rules": { | ||
"jsdoc/require-jsdoc": "off" | ||
} | ||
} |
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,35 @@ | ||
export default function apiFetch (resource, init = {}) { | ||
// add XKit header to all API requests | ||
init.headers ??= {}; | ||
init.headers['X-XKit'] = '1'; | ||
|
||
// convert all keys in the body to snake_case | ||
if (init.body !== undefined) { | ||
const objects = [init.body]; | ||
|
||
while (objects.length !== 0) { | ||
const currentObjects = objects.splice(0); | ||
|
||
currentObjects.forEach(obj => { | ||
Object.keys(obj).forEach(key => { | ||
const snakeCaseKey = key | ||
.replace(/^[A-Z]/, match => match.toLowerCase()) | ||
.replace(/[A-Z]/g, match => `_${match.toLowerCase()}`); | ||
|
||
if (snakeCaseKey !== key) { | ||
obj[snakeCaseKey] = obj[key]; | ||
delete obj[key]; | ||
} | ||
}); | ||
}); | ||
|
||
objects.push( | ||
...currentObjects | ||
.flatMap(Object.values) | ||
.filter(value => value instanceof Object) | ||
); | ||
} | ||
} | ||
|
||
return window.tumblr.apiFetch(resource, init); | ||
} |
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,21 @@ | ||
export default function controlTagsInput ({ add, remove }) { | ||
add = add.map(tag => tag.trim()).filter((tag, index, array) => array.indexOf(tag) === index); | ||
|
||
const selectedTagsElement = document.getElementById('selected-tags'); | ||
if (!selectedTagsElement) { return; } | ||
|
||
const reactKey = Object.keys(selectedTagsElement).find(key => key.startsWith('__reactFiber')); | ||
let fiber = selectedTagsElement[reactKey]; | ||
|
||
while (fiber !== null) { | ||
let tags = fiber.stateNode?.state?.tags; | ||
if (Array.isArray(tags)) { | ||
tags.push(...add.filter(tag => tags.includes(tag) === false)); | ||
tags = tags.filter(tag => remove.includes(tag) === false); | ||
fiber.stateNode.setState({ tags }); | ||
break; | ||
} else { | ||
fiber = fiber.return; | ||
} | ||
} | ||
} |
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 @@ | ||
export default () => window.tumblr.getCssMap(); |
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,14 @@ | ||
export default function getNotificationProps () { | ||
const notificationElement = this; | ||
const reactKey = Object.keys(notificationElement).find(key => key.startsWith('__reactFiber')); | ||
let fiber = notificationElement[reactKey]; | ||
|
||
while (fiber !== null) { | ||
const props = fiber.memoizedProps || {}; | ||
if (props?.notification !== undefined) { | ||
return props; | ||
} else { | ||
fiber = fiber.return; | ||
} | ||
} | ||
} |
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 @@ | ||
const moduleCache = {}; | ||
|
||
document.documentElement.addEventListener('xkitinjectionrequest', async event => { | ||
const { detail, target } = event; | ||
const { id, path, args } = JSON.parse(detail); | ||
|
||
try { | ||
moduleCache[path] ??= await import(path); | ||
const func = moduleCache[path].default; | ||
|
||
const result = await func.apply(target, args); | ||
target.dispatchEvent( | ||
new CustomEvent('xkitinjectionresponse', { detail: JSON.stringify({ id, result }) }) | ||
); | ||
} catch (exception) { | ||
target.dispatchEvent( | ||
new CustomEvent('xkitinjectionresponse', { | ||
detail: JSON.stringify({ | ||
id, | ||
exception: { | ||
message: exception.message, | ||
name: exception.name, | ||
stack: exception.stack, | ||
...exception | ||
} | ||
}) | ||
}) | ||
); | ||
} | ||
}); |
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 @@ | ||
export default () => window.tumblr.languageData; |
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 @@ | ||
export default location => window.tumblr.navigate(location); |
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 @@ | ||
export default function postRequest (resource, body) { | ||
return fetch(resource, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, | ||
body | ||
}).then(async response => | ||
response.ok ? response.json() : Promise.reject(await response.json()) | ||
); | ||
} |
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 @@ | ||
export default function testHeaderElement (selector) { | ||
const menuElement = this; | ||
const reactKey = Object.keys(menuElement).find(key => key.startsWith('__reactFiber')); | ||
let fiber = menuElement[reactKey]; | ||
|
||
while (fiber !== null) { | ||
if (fiber.elementType === 'header') { | ||
return fiber.stateNode.matches(selector); | ||
} else { | ||
fiber = fiber.return; | ||
} | ||
} | ||
} |
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,14 @@ | ||
export default function unburyBlog () { | ||
const element = this; | ||
const reactKey = Object.keys(element).find(key => key.startsWith('__reactFiber')); | ||
let fiber = element[reactKey]; | ||
|
||
while (fiber !== null) { | ||
const { blog, blogSettings } = fiber.memoizedProps || {}; | ||
if (blog ?? blogSettings) { | ||
return blog ?? blogSettings; | ||
} else { | ||
fiber = fiber.return; | ||
} | ||
} | ||
} |
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,14 @@ | ||
export default function unburyNotification () { | ||
const notificationElement = this; | ||
const reactKey = Object.keys(notificationElement).find(key => key.startsWith('__reactFiber')); | ||
let fiber = notificationElement[reactKey]; | ||
|
||
while (fiber !== null) { | ||
const { notification } = fiber.memoizedProps || {}; | ||
if (notification !== undefined) { | ||
return notification; | ||
} else { | ||
fiber = fiber.return; | ||
} | ||
} | ||
} |
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,14 @@ | ||
export default function unburyTimelineObject () { | ||
const postElement = this; | ||
const reactKey = Object.keys(postElement).find(key => key.startsWith('__reactFiber')); | ||
let fiber = postElement[reactKey]; | ||
|
||
while (fiber !== null) { | ||
const { timelineObject } = fiber.memoizedProps || {}; | ||
if (timelineObject !== undefined) { | ||
return timelineObject; | ||
} else { | ||
fiber = fiber.return; | ||
} | ||
} | ||
} |
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.