User:Bosco/Unsigned helper.js: Difference between revisions
From Test Wiki
Content deleted Content added
m Bosco moved page User:Bosco/User:Andrybak/Scripts/Unsigned helper.js to User:Bosco/Unsigned helper.js without leaving a redirect |
mNo edit summary |
||
| Line 4: | Line 4: | ||
(function () { |
(function () { |
||
const DEBUG = false; |
const DEBUG = false; |
||
const LOG_PREFIX = `[ |
const LOG_PREFIX = `[簽名工具]:`; |
||
function error(...toLog) { |
function error(...toLog) { |
||
| Line 22: | Line 22: | ||
} |
} |
||
const months = [' |
const months = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']; |
||
const CONFIG = { |
const CONFIG = { |
||
undated: 'Undated', // [[Template:Undated]] |
undated: 'Undated', // [[Template:Undated]] |
||
unsignedLoggedIn: ' |
unsignedLoggedIn: '未签名', // [[Template:Unsigned]] |
||
unsignedIp: ' |
unsignedIp: '未签名', // [[Template:Unsigned]] |
||
}; |
}; |
||
if (mw.config.get('wgAction') !== 'edit' && mw.config.get('wgAction') !== 'submit' && document.getElementById("editform") == null) { |
if (mw.config.get('wgAction') !== 'edit' && mw.config.get('wgAction') !== 'submit' && document.getElementById("editform") == null) { |
||
info(' |
info('未編輯頁面。暫停中。'); |
||
return; |
return; |
||
} |
} |
||
info(' |
info('載入中...'); |
||
function formatErrorSpan(errorMessage) { |
function formatErrorSpan(errorMessage) { |
||
return `<span style="color:maroon;"><b> |
return `<span style="color:maroon;"><b>錯誤:</b> ${errorMessage}</span>`; |
||
} |
} |
||
| Line 303: | Line 303: | ||
async function exponentialSearch(lower, upper, candidateIndex, testFunc) { |
async function exponentialSearch(lower, upper, candidateIndex, testFunc) { |
||
if (upper === null && lower === candidateIndex) { |
if (upper === null && lower === candidateIndex) { |
||
throw new Error(` |
throw new Error(`exponentialSearch 的錯誤參數(${lower}, ${upper}, ${candidateIndex}).`); |
||
} |
} |
||
if (lower === upper && lower === candidateIndex) { |
if (lower === upper && lower === candidateIndex) { |
||
throw new Error(" |
throw new Error("不能找到"); |
||
} |
} |
||
const progressMessage = `Examining [${lower}, ${upper ? upper : '...'}]. Current candidate: ${candidateIndex}`; |
const progressMessage = `Examining [${lower}, ${upper ? upper : '...'}]. Current candidate: ${candidateIndex}`; |
||
| Line 357: | Line 357: | ||
if (startRevision == undefined) { |
if (startRevision == undefined) { |
||
if (startIndex === 0) { |
if (startIndex === 0) { |
||
reject(" |
reject("不能找到最新版本。此頁面存在嗎?"); |
||
} else { |
} else { |
||
reject(` |
reject(`不能尋找開始版本 (版本=${startIndex}).`); |
||
} |
} |
||
return; |
return; |
||
| Line 366: | Line 366: | ||
const latestFullRevision = await this.#contentLoader.loadContent(startIndex); |
const latestFullRevision = await this.#contentLoader.loadContent(startIndex); |
||
if (!latestFullRevision.slots.main.content.includes(text)) { |
if (!latestFullRevision.slots.main.content.includes(text)) { |
||
reject(" |
reject("不能尋找最新版本的內容。你編輯了嗎?"); |
||
return; |
return; |
||
} |
} |
||
| Line 383: | Line 383: | ||
* ? |
* ? |
||
*/ |
*/ |
||
warn(' |
warn('測試功能:不能載入candidateIndex的內容 = ' + candidateIndex); |
||
return undefined; |
return undefined; |
||
} |
} |
||
| Line 389: | Line 389: | ||
return candidateFullRevision.slots.main.content.includes(text); |
return candidateFullRevision.slots.main.content.includes(text); |
||
} catch (e) { |
} catch (e) { |
||
reject(' |
reject('測試內容: ' + e); |
||
} |
} |
||
}); |
}); |
||
if (foundIndex === undefined) { |
if (foundIndex === undefined) { |
||
reject(" |
reject("不能尋找這個內容"); |
||
return; |
return; |
||
} |
} |
||
| Line 539: | Line 539: | ||
// TODO maybe migrate to https://www.mediawiki.org/wiki/OOUI/Windows/Message_Dialogs |
// TODO maybe migrate to https://www.mediawiki.org/wiki/OOUI/Windows/Message_Dialogs |
||
const mainDialog = $('<div> |
const mainDialog = $('<div>檢查中...</div>').dialog({ |
||
buttons: { |
buttons: { |
||
Cancel: function () { |
Cancel: function () { |
||
| Line 607: | Line 607: | ||
"The ", |
"The ", |
||
$('<a>').prop({ |
$('<a>').prop({ |
||
href: ' |
href: '/index.php?diff=prev&oldid=' + revid, |
||
target: '_blank' |
target: '_blank' |
||
}).text(` |
}).text(`已尋找版本 (版本=${searcherResult.index})`), |
||
" may be a revert: ", |
" may be a revert: ", |
||
comment |
comment |
||
| Line 630: | Line 630: | ||
function formatSizeChange(afterSize, beforeSize) { |
function formatSizeChange(afterSize, beforeSize) { |
||
const change = afterSize - beforeSize; |
const change = afterSize - beforeSize; |
||
const title = `${afterSize} |
const title = `編輯後共${afterSize}位元組`; |
||
const titleAttribute = `title="${title}"`; |
const titleAttribute = `title="${title}"`; |
||
let style = ''; |
let style = ''; |
||
| Line 662: | Line 662: | ||
"Found a revision: ", |
"Found a revision: ", |
||
$('<a>').prop({ |
$('<a>').prop({ |
||
href: ' |
href: '/index.php?diff=prev&oldid=' + revid, |
||
target: '_blank' |
target: '_blank' |
||
}).text(`[[Special:Diff/${revid}]] (index=${searcherResult.index})`), |
}).text(`[[Special:Diff/${revid}]] (index=${searcherResult.index})`), |
||
| Line 678: | Line 678: | ||
function searchFromIndex(index) { |
function searchFromIndex(index) { |
||
if (selection == undefined || selection == '') { |
if (selection == undefined || selection == '') { |
||
mainDialog.html(formatErrorSpan(" |
mainDialog.html(formatErrorSpan("請選擇一個未簽名的訊息") + |
||
" Selected: <code>" + originalSelection + "</code>"); |
" Selected: <code>" + originalSelection + "</code>"); |
||
return; |
return; |
||
| Line 704: | Line 704: | ||
reportNormalSearcherResultToUser(searcherResult, useCallback, keepLookingCallback, cancelCallback); |
reportNormalSearcherResultToUser(searcherResult, useCallback, keepLookingCallback, cancelCallback); |
||
}, rejection => { |
}, rejection => { |
||
error(` |
error(`搜尋器不能尋找已要求的索引=${index}. Got error:`, rejection); |
||
if (!mainDialog.dialog('isOpen')) { |
if (!mainDialog.dialog('isOpen')) { |
||
// user clicked [cancel] |
// user clicked [cancel] |
||