/
TON618OFF
/
FinalPWHTML
Обзор
Документация
Войти
/
TON618OFF
/
FinalPWHTML
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
node_modules/@pmmmwh/react-refresh-webpack-plugin/sockets/utils/getCurrentScriptSource.js
30 строк
1 KB
TON618OFF
не ну это ваще
23 июн 2024, 00:30
23 июн 2024, 00:30
e27ae20
Код
Авторство
О чём код?
/** * Gets the source (i.e. host) of the script currently running. * @returns {string} */ function getCurrentScriptSource() { // `document.currentScript` is the most accurate way to get the current running script, // but is not supported in all browsers (most notably, IE). if ('currentScript' in document) { // In some cases, `document.currentScript` would be `null` even if the browser supports it: // e.g. asynchronous chunks on Firefox. // We should not fallback to the list-approach as it would not be safe. if (document.currentScript == null) return; return document.currentScript.getAttribute('src'); } // Fallback to getting all scripts running in the document, // and finding the last one injected. else { const scriptElementsWithSrc = Array.prototype.filter.call( document.scripts || [], function (elem) { return elem.getAttribute('src'); } ); if (!scriptElementsWithSrc.length) return; const currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1]; return currentScript.getAttribute('src'); } } module.exports = getCurrentScriptSource;