mirror of
https://github.com/zhigang1992/react-native-paper.git
synced 2026-05-24 01:09:26 +08:00
Deploy to GitHub Pages: 6cc83d2be2
This commit is contained in:
67
scripts/snack.js
Normal file
67
scripts/snack.js
Normal file
@@ -0,0 +1,67 @@
|
||||
/* eslint-disable strict, no-var, vars-on-top, prefer-template */
|
||||
|
||||
'use strict';
|
||||
|
||||
function appendSnackLink() {
|
||||
var usage = Array.from(document.querySelectorAll('h2')).find(
|
||||
h => h.textContent === 'Usage'
|
||||
);
|
||||
|
||||
if (usage) {
|
||||
var pre = usage.nextElementSibling;
|
||||
|
||||
while (
|
||||
pre.firstChild.tagName !== 'CODE' ||
|
||||
pre.firstChild.className !== 'language-js'
|
||||
) {
|
||||
pre = pre.nextElementSibling;
|
||||
}
|
||||
|
||||
if (!pre) {
|
||||
return;
|
||||
}
|
||||
|
||||
var link;
|
||||
var insert = true;
|
||||
|
||||
if (pre.nextElementSibling && pre.nextElementSibling.dataset.snack) {
|
||||
link = pre.nextElementSibling;
|
||||
insert = false;
|
||||
} else {
|
||||
link = document.createElement('a');
|
||||
link.dataset.snack = true;
|
||||
link.target = '_blank';
|
||||
link.innerHTML =
|
||||
'Try this example on Snack <svg width="14px" height="14px" viewBox="0 0 16 16" style="vertical-align: -1px"><g stroke="none" stroke-width="1" fill="none"><polyline stroke="currentColor" points="8.5 0.5 15.5 0.5 15.5 7.5"></polyline><path d="M8,8 L15.0710678,0.928932188" stroke="currentColor"></path><polyline stroke="currentColor" points="9.06944444 3.5 1.5 3.5 1.5 14.5 12.5 14.5 12.5 6.93055556"></polyline></g></svg>';
|
||||
}
|
||||
|
||||
var href =
|
||||
'https://snack.expo.io?name=' +
|
||||
encodeURIComponent(document.title + ' Example') +
|
||||
'&description=' +
|
||||
encodeURIComponent(window.location.href) +
|
||||
'&code=' +
|
||||
encodeURIComponent(pre.textContent);
|
||||
|
||||
if (link.href === href) {
|
||||
return;
|
||||
}
|
||||
|
||||
link.href = href;
|
||||
|
||||
if (insert) {
|
||||
pre.insertAdjacentElement('afterend', link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
appendSnackLink();
|
||||
|
||||
var mutationObserver = new MutationObserver(mutations => {
|
||||
mutations.forEach(appendSnackLink);
|
||||
});
|
||||
|
||||
mutationObserver.observe(document.documentElement, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
});
|
||||
Reference in New Issue
Block a user