tb115 segmenter removed. see #616
This commit is contained in:
parent
72737d538b
commit
6463e180af
3 changed files with 1 additions and 115 deletions
|
|
@ -1,65 +0,0 @@
|
||||||
/*
|
|
||||||
* ThunderAI [https://micz.it/thunderbird-addon-thunderai/]
|
|
||||||
* Copyright (C) 2024 - 2026 Mic (m@micz.it)
|
|
||||||
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
// Firefox 115 and, consequently, Thunderbird 115 are not compatible with Intl.Segmenter.
|
|
||||||
// ChatGPT is using Intl.Segmenter, so we have to do something about it or it won't work...
|
|
||||||
|
|
||||||
// console.log("[ThunderAI] Intl.Segmenter: " + Intl.Segmenter);
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
if('Segmenter' in Intl){
|
|
||||||
// console.log('[ThunderAI] TB128+ detected. Intl.Segmenter is already supported.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Creates a <script> element to inject polyfill.js into the page context
|
|
||||||
const script = document.createElement('script');
|
|
||||||
script.src = browser.runtime.getURL('js/tb115_segmenter/tb115_polyfill.js');
|
|
||||||
script.onload = function() {
|
|
||||||
// Remove the script once loaded for cleanup
|
|
||||||
this.remove();
|
|
||||||
};
|
|
||||||
script.onerror = function() {
|
|
||||||
console.error('[ThunderAI] Error loading Intl.Segmenter polyfill.');
|
|
||||||
};
|
|
||||||
(document.head || document.documentElement).appendChild(script);
|
|
||||||
})();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function isThunderbird128OrGreater(){
|
|
||||||
try {
|
|
||||||
const info = await browser.runtime.getBrowserInfo();
|
|
||||||
const version = info.version;
|
|
||||||
return compareThunderbirdVersions(version, '128.0') >= 0;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('[ThunderAI] Error retrieving browser information:', error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function compareThunderbirdVersions(v1, v2) {
|
|
||||||
const v1parts = v1.split('.').map(Number);
|
|
||||||
const v2parts = v2.split('.').map(Number);
|
|
||||||
|
|
||||||
for (let i = 0; i < Math.max(v1parts.length, v2parts.length); i++) {
|
|
||||||
const v1part = v1parts[i] || 0;
|
|
||||||
const v2part = v2parts[i] || 0;
|
|
||||||
if (v1part > v2part) return 1;
|
|
||||||
if (v1part < v2part) return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
/*
|
|
||||||
* ThunderAI [https://micz.it/thunderbird-addon-thunderai/]
|
|
||||||
* Copyright (C) 2024 - 2026 Mic (m@micz.it)
|
|
||||||
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
// Firefox 115 and, consequently, Thunderbird 115 are not compatible with Intl.Segmenter.
|
|
||||||
// ChatGPT is using Intl.Segmenter, so we have to do something about it or it won't work...
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
if (!('Segmenter' in Intl)) {
|
|
||||||
class Segmenter {
|
|
||||||
constructor(locale = 'en', options = { granularity: 'grapheme' }) {
|
|
||||||
this.locale = locale;
|
|
||||||
this.granularity = options.granularity || 'grapheme';
|
|
||||||
}
|
|
||||||
|
|
||||||
segment(text) {
|
|
||||||
switch (this.granularity) {
|
|
||||||
case 'word':
|
|
||||||
return text.split(/\s+/).filter(word => word.length > 0).map(word => ({ segment: word }));
|
|
||||||
case 'grapheme':
|
|
||||||
return Array.from(text).map(char => ({ segment: char }));
|
|
||||||
case 'sentence':
|
|
||||||
return text.split(/(?<=[.!?])\s+/).map(sentence => ({ segment: sentence }));
|
|
||||||
default:
|
|
||||||
return [{ segment: text }];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Intl.Segmenter = Segmenter;
|
|
||||||
// console.log('Intl.Segmenter polyfill correctly loaded.');
|
|
||||||
}
|
|
||||||
// else {
|
|
||||||
// console.log('Intl.Segmenter is already supported.');
|
|
||||||
// }
|
|
||||||
})();
|
|
||||||
|
|
@ -65,7 +65,7 @@
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": ["https://*.chatgpt.com/*"],
|
"matches": ["https://*.chatgpt.com/*"],
|
||||||
"js": ["js/tb115_segmenter/tb115_loader.js","js/lib/diff.js"],
|
"js": ["js/lib/diff.js"],
|
||||||
"all_frames": true,
|
"all_frames": true,
|
||||||
"run_at": "document_start"
|
"run_at": "document_start"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue