MediaWiki:Common.js: различия между версиями
добавим также валидацию размеров для ВК и защиту iframe |
Откат правки 362378 участника Тэйтанка-птекила (обс.) Метка: отмена |
||
| (не показана 21 промежуточная версия этого же участника) | |||
| Строка 1: | Строка 1: | ||
/* Нигилистические фокусы (см. шаблон {{Нигилизм}}) */ | /* Нигилистические фокусы (см. шаблон {{tl|Нигилизм}}) */ | ||
$(function () { | $(function () { | ||
var nihilism = $('#nihilism'); | var nihilism = $('#nihilism'); | ||
| Строка 83: | Строка 83: | ||
width = parseInt(width) || 560; | width = parseInt(width) || 560; | ||
height = parseInt(height) || 315; | height = parseInt(height) || 315; | ||
if (width > | if (width > 1920) width = 1920; | ||
if (height < 100) height = 100; | if (height < 100) height = 100; | ||
if (height > | if (height > 1080) height = 1080; | ||
if (oid && id && oid !== 'null' && id !== 'null' && /^[ | if (oid && id && oid !== 'null' && id !== 'null' && /^[a-zA-Z0-9_-]{1,100}$/.test(oid) && /^[-_a-zA-Z0-9]+$/.test(id)) { | ||
var iframe = document.createElement('iframe'); | var iframe = document.createElement('iframe'); | ||
iframe.src = 'https://vk.com/video_ext.php?oid=' + encodeURIComponent(oid) + '&id=' + encodeURIComponent(id); | iframe.src = 'https://vk.com/video_ext.php?oid=' + encodeURIComponent(oid) + '&id=' + encodeURIComponent(id); | ||
| Строка 97: | Строка 97: | ||
iframe.sandbox = 'allow-scripts allow-same-origin allow-presentation allow-fullscreen'; | iframe.sandbox = 'allow-scripts allow-same-origin allow-presentation allow-fullscreen'; | ||
iframe.allow = 'fullscreen'; | iframe.allow = 'fullscreen'; | ||
iframe.referrerPolicy = 'no-referrer'; | |||
iframe.loading = 'lazy'; | |||
iframe.style.border = 'none'; | iframe.style.border = 'none'; | ||
| Строка 105: | Строка 106: | ||
container.appendChild(iframe); | container.appendChild(iframe); | ||
} else { | } else { | ||
var errorDiv = document.createElement('div'); | |||
errorDiv.style.color = 'red'; | |||
errorDiv.style.padding = '10px'; | |||
errorDiv.style.textAlign = 'center'; | |||
errorDiv.style.border = '1px solid'; | |||
errorDiv.style.backgroundColor = '#fff'; | |||
errorDiv.style.fontFamily = 'Arial, sans-serif'; | |||
errorDiv.style.fontSize = '14px'; | |||
errorDiv.style.margin = '5px 0'; | |||
errorDiv.textContent = 'Ошибка: неверные параметры видео'; | |||
while (container.firstChild) { | |||
container.removeChild(container.firstChild); | |||
} | |||
container.appendChild(errorDiv); | |||
} | } | ||
} | } | ||
| Строка 113: | Строка 131: | ||
} else { | } else { | ||
initVKVideo(); | initVKVideo(); | ||
} | } | ||
})(); | })(); | ||