function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
function obRemAnnots () {
var remove = [];
var annots = this.getAnnots();
for (var i = 0; i < annots.length; i++) {
if (annots[i].author == 'Annot Robout') {
remove.push(annots[i]);
}
}
remove.reverse();
for (var i = 0; i < remove.length; i++) {
remove[i].destroy();
}
}
function obAddAnnots () {
var annots = this.getAnnots();
var remove = [];
for (var i = 0; i < annots.length; i++) {
if (annots[i].type == 'Highlight' && annots[i].contents.indexOf('Change into: ') == 0) {
remove.push(annots[i]);
var page = annots[i].page;
var rect = annots[i].rect;
var height = rect[3] - rect[1];
var quads = annots[i].quads
var contents = annots[i].contents.replace('Change into: ', '');
var uid = uuidv4();
this.addAnnot({
page: page,
type: 'StrikeOut',
quads: quads,
author: 'Annot Robout',
contents: '',
inReplyTo: uid,
intent: 'StrikeOutTextEdit',
strokeColor: ['RGB',0,0,1],
refType: 'Group',
style: 'S',
subject: 'Replace Text',
});
this.addAnnot({
page: page,
type: 'Caret',
rect: [rect[2] - height / 2, rect[1], rect[2], rect[3] - height / 1.5],
author: 'Annot Robout',
name: uid,
intent: 'Replace',
contents: contents,
refType: 'R',
style: 'S',
subject: 'Replace Text',
});
}
}
remove.reverse();
for (var i = 0; i < remove.length; i++) {
remove[i].destroy();
}
}
obRemAnnots();
obAddAnnots();