MediaWiki:NormalizeMarcData.js e MediaWiki:AuthorityLinks.js: mudanças entre as páginas
(Diferenças entre páginas)
Ir para navegação
Ir para pesquisar
(Criou página com '→jshint esversion: 8: function rmCarriageReturn() { const textareas = document.body.querySelectorAll('textarea'); textareas.forEach((textarea) => { const element = textarea; element.value = element.value.replace('�', ''); }); } function rmHtmlTags() { const textareas = document.body.querySelectorAll('textarea'); textareas.forEach((textarea) => { const element = textarea; element.value = element.value.replace( /<(?:"[^"]*"['"]*|'[^'...') |
(Criou página com '→jshint esversion: 8: function authorityLinks() { let tag = ''; let tagFromDropdown = ''; const inputs = document.body.querySelectorAll( '.instanceMain div table .oo-ui-inputWidget-input', ); inputs.forEach((elem) => { const authorityLink = document.createElement('a'); authorityLink.setAttribute( 'title', 'Abre uma nova aba para criar ou editar um registro de autoridade', ); authorityLink.setAttribute('target', '_blank');...') |
||
Linha 1: | Linha 1: | ||
/*jshint esversion: 8 */ |
/* jshint esversion: 8 */ |
||
function |
function authorityLinks() { |
||
let tag = ''; |
|||
const textareas = document.body.querySelectorAll('textarea'); |
|||
let tagFromDropdown = ''; |
|||
textareas.forEach((textarea) => { |
|||
const inputs = document.body.querySelectorAll( |
|||
'.instanceMain div table .oo-ui-inputWidget-input', |
|||
element.value = element.value.replace(' ', ''); |
|||
); |
|||
inputs.forEach((elem) => { |
|||
} |
|||
const authorityLink = document.createElement('a'); |
|||
authorityLink.setAttribute( |
|||
function rmHtmlTags() { |
|||
'title', |
|||
const textareas = document.body.querySelectorAll('textarea'); |
|||
'Abre uma nova aba para criar ou editar um registro de autoridade', |
|||
textareas.forEach((textarea) => { |
|||
const element = textarea; |
|||
element.value = element.value.replace( |
|||
/<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g, |
|||
'', |
|||
); |
); |
||
authorityLink.setAttribute('target', '_blank'); |
|||
}); |
|||
authorityLink.innerText = 'Criar registro de autoridade'; |
|||
} |
|||
authorityLink.style.display = 'none'; |
|||
const createAuthorityLink = elem |
|||
function rmTxtFromHiddenFields() { |
|||
.closest('table') |
|||
const spans = document.body.querySelectorAll('span.hiddenByPF'); |
|||
.querySelector('.createAuthorityLink'); |
|||
spans.forEach((elem) => { |
|||
createAuthorityLink.innerHTML = ''; |
|||
elem.querySelectorAll('.input.oo-ui-inputWidget-input').forEach((input) => { |
|||
createAuthorityLink.appendChild(authorityLink); |
|||
const element = input; |
|||
element.value = ''; |
|||
}); |
|||
elem.querySelectorAll('textarea').forEach((input) => { |
|||
const element = input; |
|||
element.value = ''; |
|||
}); |
|||
}); |
|||
} |
|||
const pattern1 = /\$0\sA\d{6}/; |
|||
function normalizeInput() { |
|||
const pattern2 = /\$0\s\(BN\)\d{9}/; |
|||
const instanceMains = document.body.querySelectorAll( |
|||
'.instanceMain div table', |
|||
elem.addEventListener('focusout', () => { |
|||
); |
|||
// if already recorded |
|||
instanceMains.forEach((instanceMain) => { |
|||
if (pattern1.test(elem.value)) { |
|||
instanceMain |
|||
// build the URL for Wikincat aut record edit |
|||
.querySelectorAll('.oo-ui-inputWidget-input') |
|||
authorityLink.innerText = 'Editar autoridade'; |
|||
.forEach((input) => { |
|||
authorityLink.setAttribute( |
|||
'href', |
|||
normalizedInput.value = normalizedInput.value |
|||
`/wiki/Special:FormEdit/AutRecord/Autoridade:${elem.value.match( |
|||
// "$a Bar \n$b Baz" > " $a Bar $b Baz" |
|||
/A\d{6}/, |
|||
)}`, |
|||
// "$a Bar\nFoo" > "$a Bar Foo" ou "$a Bar Foo" > "$a Bar Foo" |
|||
); |
|||
} else if (pattern2.test(elem.value)) { |
|||
// replace "|" by "%7C" (Ex.: http://viaf.org/processed/WKP|Q2484404) |
|||
// build the URL for BN aut record view |
|||
.replace('|', '%7C'); |
|||
authorityLink.innerText = 'Ver registro de autoridade na BN'; |
|||
}); |
|||
authorityLink.setAttribute( |
|||
instanceMain.querySelectorAll('textarea').forEach((textarea) => { |
|||
'href', |
|||
`http://acervo.bn.gov.br/sophia_web/autoridade/detalhe/${elem.value.match( |
|||
textarea.value = normalizedInput.value |
|||
/\d{9}/, |
|||
)}`, |
|||
); |
|||
// "$a Bar\nFoo" > "$a Bar Foo" ou "$a Bar Foo" > "$a Bar Foo" |
|||
} else { |
|||
.replace(/\n|\s\s+|\t/g, ' ') |
|||
// |
// find the tag value from the chosen dropdown |
||
tagFromDropdown = |
|||
elem |
|||
.closest('.instanceMain') |
|||
.querySelector('.oo-ui-inputWidget-input') |
|||
.getAttribute('title') || '00x'; |
|||
tagFromDropdown = tagFromDropdown.substring(0, 3); |
|||
// find the tag value from checked radio button |
|||
const tagFromRadio = elem |
|||
.closest('.instanceMain') |
|||
.querySelector( |
|||
"input[origname='Field[authorityType]']:checked", |
|||
).value; |
|||
const authorityTypes = { |
|||
Pessoa: '100', |
|||
'Entidade coletiva': '110', |
|||
Evento: '111', |
|||
'Título uniforme': '130', |
|||
Tópico: '150', |
|||
Local: '151', |
|||
}; |
|||
if (tagFromRadio in authorityTypes) { |
|||
tag = authorityTypes[tagFromRadio]; |
|||
} |
|||
// declare the indicators default values |
|||
let ind1 = elem |
|||
.closest('.instanceMain') |
|||
.querySelector("select[origname='Field[ind1]'] option:checked").value; |
|||
let ind2 = elem |
|||
.closest('.instanceMain') |
|||
.querySelector("select[origname='Field[ind2]'] option:checked").value; |
|||
// declare the 008 field default values |
|||
let directOrIndirectGeogSubdiv = ''; // 06 |
|||
let kindOfRecord = ''; // 09 |
|||
let descriptiveCatalogingRules = 'c'; // 10 |
|||
let subjectHeadingSystem = 'n'; // 11 |
|||
let typeOfSeries = 'n'; // 12 |
|||
let numberedOrUnnumberedSeries = 'n'; // 13 |
|||
let headingUseMainOrAddedEntry = 'a'; // 14 |
|||
let headingUseSubjectAddedEntry = 'a'; // 15 |
|||
let headingUseSeriesAddedEntry = 'b'; // 16 |
|||
let typeOfSubjectSubdivision = 'n'; // 17 |
|||
let undifferentiatedPersonalName = 'n'; // 32 |
|||
let levelOfEstablishment = 'a'; // 33 |
|||
// set the 008 field and indicadors specific values |
|||
if (tag === '100') { |
|||
undifferentiatedPersonalName = 'a'; |
|||
ind2 = ''; |
|||
} |
|||
if (tag === '110') { |
|||
// in case of autocomplete of 260 |
|||
if (tagFromDropdown === '260') { |
|||
directOrIndirectGeogSubdiv = 'n'; |
|||
kindOfRecord = 'b'; |
|||
headingUseMainOrAddedEntry = 'b'; |
|||
headingUseSubjectAddedEntry = 'b'; |
|||
levelOfEstablishment = 'n'; |
|||
ind1 = '1'; |
|||
} |
|||
ind2 = ''; |
|||
} |
|||
if (tag === '111') { |
|||
ind1 = '2'; |
|||
ind2 = ''; |
|||
} |
|||
if (tag === '130') { |
|||
typeOfSeries = 'a'; |
|||
numberedOrUnnumberedSeries = 'b'; |
|||
headingUseSeriesAddedEntry = 'a'; |
|||
if ( |
|||
tagFromDropdown === '130' || |
|||
tagFromDropdown === '630' || |
|||
tagFromDropdown === '730' |
|||
) { |
|||
ind2 = ind1; // an inverted value happens here, see and |
|||
ind1 = ''; // compare bib. and auth. 130 MARC definitions |
|||
} |
|||
ind1 = ''; |
|||
} |
|||
if (tag === '150' || tag === '151') { |
|||
descriptiveCatalogingRules = 'n'; |
|||
subjectHeadingSystem = 'z'; |
|||
headingUseMainOrAddedEntry = 'b'; |
|||
ind1 = ''; // 150 and 151 indicators must be empty in |
|||
ind2 = ''; // authority MARC records |
|||
if (tag === '151') { |
|||
typeOfSubjectSubdivision = 'd'; |
|||
} |
|||
} |
|||
// build the URL |
|||
const autRecordParams = { |
|||
AutRecord: { |
|||
directOrIndirectGeogSubdiv, |
|||
kindOfRecord, |
|||
descriptiveCatalogingRules, |
|||
subjectHeadingSystem, |
|||
typeOfSeries, |
|||
numberedOrUnnumberedSeries, |
|||
headingUseMainOrAddedEntry, |
|||
headingUseSubjectAddedEntry, |
|||
headingUseSeriesAddedEntry, |
|||
typeOfSubjectSubdivision, |
|||
undifferentiatedPersonalName, |
|||
levelOfEstablishment, |
|||
}, |
|||
Field: { |
|||
1: { |
|||
tag: '040', |
|||
data: '$a BR-FlWIK $b por $c BR-FlWIK $d BR-FlUSC', |
|||
}, |
|||
2: { |
|||
tag, |
|||
ind1, |
|||
ind2, |
|||
data: elem.value, |
|||
}, |
|||
3: { |
|||
tag: '670', |
|||
data: '$a ', |
|||
}, |
|||
}, |
|||
}; |
|||
const url = new URL( |
|||
`${window.location.origin}/wiki/Special:FormEdit/AutRecord`, |
|||
); |
|||
// function to transform a 3rd level object to URL query strings |
|||
const makeUrlParams = (obj) => { |
|||
for (const [key, value] of Object.entries(obj)) { |
|||
if (typeof value === 'object') { |
|||
for (const [key2, value2] of Object.entries(value)) { |
|||
if (typeof value2 === 'object') { |
|||
for (const [key3, value3] of Object.entries(value2)) { |
|||
url.searchParams.set(`${key}[${key2}][${key3}]`, value3); |
|||
} |
|||
} else { |
|||
url.searchParams.set(`${key}[${key2}]`, value2); |
|||
} |
|||
} |
|||
} else { |
|||
url.searchParams.set(key, value); |
|||
} |
|||
} |
|||
}; |
|||
makeUrlParams(autRecordParams); |
|||
authorityLink.innerText = 'Criar registro de autoridade'; |
|||
authorityLink.setAttribute('href', url.pathname + url.search); |
|||
} |
|||
authorityLink.style.display = ''; |
|||
}); |
}); |
||
}); |
}); |
Edição das 20h07min de 14 de março de 2024
/* jshint esversion: 8 */
function authorityLinks() {
let tag = '';
let tagFromDropdown = '';
const inputs = document.body.querySelectorAll(
'.instanceMain div table .oo-ui-inputWidget-input',
);
inputs.forEach((elem) => {
const authorityLink = document.createElement('a');
authorityLink.setAttribute(
'title',
'Abre uma nova aba para criar ou editar um registro de autoridade',
);
authorityLink.setAttribute('target', '_blank');
authorityLink.innerText = 'Criar registro de autoridade';
authorityLink.style.display = 'none';
const createAuthorityLink = elem
.closest('table')
.querySelector('.createAuthorityLink');
createAuthorityLink.innerHTML = '';
createAuthorityLink.appendChild(authorityLink);
const pattern1 = /\$0\sA\d{6}/;
const pattern2 = /\$0\s\(BN\)\d{9}/;
elem.addEventListener('focusout', () => {
// if already recorded
if (pattern1.test(elem.value)) {
// build the URL for Wikincat aut record edit
authorityLink.innerText = 'Editar autoridade';
authorityLink.setAttribute(
'href',
`/wiki/Special:FormEdit/AutRecord/Autoridade:${elem.value.match(
/A\d{6}/,
)}`,
);
} else if (pattern2.test(elem.value)) {
// build the URL for BN aut record view
authorityLink.innerText = 'Ver registro de autoridade na BN';
authorityLink.setAttribute(
'href',
`http://acervo.bn.gov.br/sophia_web/autoridade/detalhe/${elem.value.match(
/\d{9}/,
)}`,
);
} else {
// find the tag value from the chosen dropdown
tagFromDropdown =
elem
.closest('.instanceMain')
.querySelector('.oo-ui-inputWidget-input')
.getAttribute('title') || '00x';
tagFromDropdown = tagFromDropdown.substring(0, 3);
// find the tag value from checked radio button
const tagFromRadio = elem
.closest('.instanceMain')
.querySelector(
"input[origname='Field[authorityType]']:checked",
).value;
const authorityTypes = {
Pessoa: '100',
'Entidade coletiva': '110',
Evento: '111',
'Título uniforme': '130',
Tópico: '150',
Local: '151',
};
if (tagFromRadio in authorityTypes) {
tag = authorityTypes[tagFromRadio];
}
// declare the indicators default values
let ind1 = elem
.closest('.instanceMain')
.querySelector("select[origname='Field[ind1]'] option:checked").value;
let ind2 = elem
.closest('.instanceMain')
.querySelector("select[origname='Field[ind2]'] option:checked").value;
// declare the 008 field default values
let directOrIndirectGeogSubdiv = ''; // 06
let kindOfRecord = ''; // 09
let descriptiveCatalogingRules = 'c'; // 10
let subjectHeadingSystem = 'n'; // 11
let typeOfSeries = 'n'; // 12
let numberedOrUnnumberedSeries = 'n'; // 13
let headingUseMainOrAddedEntry = 'a'; // 14
let headingUseSubjectAddedEntry = 'a'; // 15
let headingUseSeriesAddedEntry = 'b'; // 16
let typeOfSubjectSubdivision = 'n'; // 17
let undifferentiatedPersonalName = 'n'; // 32
let levelOfEstablishment = 'a'; // 33
// set the 008 field and indicadors specific values
if (tag === '100') {
undifferentiatedPersonalName = 'a';
ind2 = '';
}
if (tag === '110') {
// in case of autocomplete of 260
if (tagFromDropdown === '260') {
directOrIndirectGeogSubdiv = 'n';
kindOfRecord = 'b';
headingUseMainOrAddedEntry = 'b';
headingUseSubjectAddedEntry = 'b';
levelOfEstablishment = 'n';
ind1 = '1';
}
ind2 = '';
}
if (tag === '111') {
ind1 = '2';
ind2 = '';
}
if (tag === '130') {
typeOfSeries = 'a';
numberedOrUnnumberedSeries = 'b';
headingUseSeriesAddedEntry = 'a';
if (
tagFromDropdown === '130' ||
tagFromDropdown === '630' ||
tagFromDropdown === '730'
) {
ind2 = ind1; // an inverted value happens here, see and
ind1 = ''; // compare bib. and auth. 130 MARC definitions
}
ind1 = '';
}
if (tag === '150' || tag === '151') {
descriptiveCatalogingRules = 'n';
subjectHeadingSystem = 'z';
headingUseMainOrAddedEntry = 'b';
ind1 = ''; // 150 and 151 indicators must be empty in
ind2 = ''; // authority MARC records
if (tag === '151') {
typeOfSubjectSubdivision = 'd';
}
}
// build the URL
const autRecordParams = {
AutRecord: {
directOrIndirectGeogSubdiv,
kindOfRecord,
descriptiveCatalogingRules,
subjectHeadingSystem,
typeOfSeries,
numberedOrUnnumberedSeries,
headingUseMainOrAddedEntry,
headingUseSubjectAddedEntry,
headingUseSeriesAddedEntry,
typeOfSubjectSubdivision,
undifferentiatedPersonalName,
levelOfEstablishment,
},
Field: {
1: {
tag: '040',
data: '$a BR-FlWIK $b por $c BR-FlWIK $d BR-FlUSC',
},
2: {
tag,
ind1,
ind2,
data: elem.value,
},
3: {
tag: '670',
data: '$a ',
},
},
};
const url = new URL(
`${window.location.origin}/wiki/Special:FormEdit/AutRecord`,
);
// function to transform a 3rd level object to URL query strings
const makeUrlParams = (obj) => {
for (const [key, value] of Object.entries(obj)) {
if (typeof value === 'object') {
for (const [key2, value2] of Object.entries(value)) {
if (typeof value2 === 'object') {
for (const [key3, value3] of Object.entries(value2)) {
url.searchParams.set(`${key}[${key2}][${key3}]`, value3);
}
} else {
url.searchParams.set(`${key}[${key2}]`, value2);
}
}
} else {
url.searchParams.set(key, value);
}
}
};
makeUrlParams(autRecordParams);
authorityLink.innerText = 'Criar registro de autoridade';
authorityLink.setAttribute('href', url.pathname + url.search);
}
authorityLink.style.display = '';
});
});
}