diff --git a/main.js b/main.js index eeb9bfe..e1e3e09 100644 --- a/main.js +++ b/main.js @@ -12,6 +12,25 @@ 'ありえね~~~!!!', ]; + const isNegativeLookBehindSupported = (() => { + try { + // A dirty test: + // - Safari (and legacy browser): deny the literal at parse phase + // - non-Safari modern browser: pass + // + // Please refer https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#browser_compatibility + // for more info. + Function("() => /(?' }, - { - from: /(?]+)\n\n+/g, - to: '
' - }, - { - from: /(?]+)((.+?)|\(.+?\))/g, - to: '$1' - }, - { - from: /(?]+)\{\{Warning\|(.+)\}\}/gi, - to: '

$1

' - }, - { - from: /(?]+)\[\[twitter:(.+)\|(.+)\]\]/gi, - to: '$2' - }, - { - from: /(?]+)\[\[tweet:(.+)\|(.+)\]\]/gi, - to: '$2' - }, - { - from: /(?]+)\{\{twitter hashtag\|(.+)\}\}/gi, - to: '#$1' - }, - { - from: /(?]+)(@)([0-9_a-z]+)/gi, - to: '$1$2' - }, - { - from: /(?]+)⬛/g, - to: '■', - }, - { - from: /(?]+)([!■✕□])/g, - to: '$1', - }, - { - from: /(?]+)♡/g, - to: "❤️", - }, - { - from: /(?]+)(?(”|"))(.+?)\k/g, - to: "$1$3$1", - }, - { - from: /(?]+)(?(\*))(.+?)\k/g, - to: "$3", - }, - { - from: /(?]+)(「.+?」|[.+?]|〔.+?〕)/g, - to: "$1", - }, - { - from: /(?]+)\[(.+):(.+)\]:?/g, - to: '

$1$2

' - }, - { - from: /(?]+)(VRChat|evil|break|learned|T1|Windows(\d+)?|i\d(\-\d+)?|Q\d+|[\??!!]+?|Twitter2?|Discord|インターネット|SAN値?(ピンチ)?|女装)/gi, - to: '$1' - }, - { - from: /(?]+)(?<=\d)(:)(?=\d)/g, - to: '$1' - }, - { - from: /(?]+)(?<=\d)(\-)(?=\d)/g, - to: '$1' - }, - { - from: /(?]+)(?<=\d)(\.)(?=\d)/g, - to: '$1' - }, - { - from: /(?]+)(?<=\d)(,)(?=\d)/g, - to: '$1' - }, - { - from: /(?]+)(\d)/g, - to: '$1' - }, ]; + if (isNegativeLookBehindSupported) { + REPLACES.push( + { + from: new RegExp("(?]+)\\n\\n+", 'g'), + to: '

' + }, + { + from: new RegExp('(?]+)((.+?)|\\(.+?\\))', 'g'), + to: '$1' + }, + { + from: new RegExp('(?]+)\\{\\{Warning\\|(.+)\\}\\}', 'gi'), + to: '

$1

' + }, + { + from: new RegExp('(?]+)\\[\\[twitter:(.+)\\|(.+)\\]\\]', 'gi'), + to: '$2' + }, + { + from: new RegExp('(?]+)\\[\\[tweet:(.+)\\|(.+)\\]\\]', 'gi'), + to: '$2' + }, + { + from: new RegExp('(?]+)\\{\\{twitter hashtag\\|(.+)\\}\\}', 'gi'), + to: '#$1' + }, + { + from: new RegExp('(?]+)(@)([0-9_a-z]+)', 'gi'), + to: '$1$2' + }, + { + from: new RegExp('(?]+)⬛', 'g'), + to: '■', + }, + { + from: new RegExp('(?]+)([!■✕□])', 'g'), + to: '$1', + }, + { + from: new RegExp('(?]+)♡', 'g'), + to: "❤️", + }, + { + from: new RegExp('(?]+)(?(”|"))(.+?)\\k', 'g'), + to: "$1$3$1", + }, + { + from: new RegExp('(?]+)(?(\\*))(.+?)\\k', 'g'), + to: "$3", + }, + { + from: new RegExp('(?]+)(「.+?」|[.+?]|〔.+?〕)', 'g'), + to: "$1", + }, + { + from: new RegExp('(?]+)\\[(.+):(.+)\\]:?', 'g'), + to: '

$1$2

' + }, + { + from: new RegExp('(?]+)(VRChat|evil|break|learned|T1|Windows(\\d+)?|i\\d(\\-\\d+)?|Q\\d+|[\\??!!]+?|Twitter2?|Discord|インターネット|SAN値?(ピンチ)?|女装)', 'gi'), + to: '$1' + }, + { + from: new RegExp('(?]+)(?<=\\d)(:)(?=\\d)', 'g'), + to: '$1' + }, + { + from: new RegExp('(?]+)(?<=\\d)(\\-)(?=\\d)', 'g'), + to: '$1' + }, + { + from: new RegExp('(?]+)(?<=\\d)(\\.)(?=\\d)', 'g'), + to: '$1' + }, + { + from: new RegExp('(?]+)(?<=\\d)(,)(?=\\d)', 'g'), + to: '$1' + }, + { + from: new RegExp('(?]+)(\\d)', 'g'), + to: '$1' + }, + ) + } + const htmlSanity = text => { const e = document.createElement('div'); e.textContent = text; @@ -150,6 +174,9 @@ document.title = `${document.title}`; let bodyHTML = htmlSanity(a.body); + if (isNegativeLookBehindSupported) { + bodyHTML = '一部置き換えが無効化されました。最新のブラウザを使ってください。' + bodyHTML + } REPLACES.forEach(v => { bodyHTML = bodyHTML.replace(v.from, v.to);