mirror of
https://github.com/marty-oehme/scripts.git
synced 2024-12-21 23:48:08 +00:00
added two more scripts
This commit is contained in:
parent
c502d6d759
commit
e27872ddc3
4 changed files with 253 additions and 0 deletions
9
note-from-bitrix-task/info.json
Normal file
9
note-from-bitrix-task/info.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "Note from Bitrix24 task",
|
||||||
|
"identifier": "note-from-bitrix-task",
|
||||||
|
"script": "note-from-bitrix-task.qml",
|
||||||
|
"authors": ["@pbek"],
|
||||||
|
"version": "0.0.1",
|
||||||
|
"minAppVersion": "17.05.6",
|
||||||
|
"description" : "This script creates a menu item and a button that parses the text that was copied from a task webpage of the webservice <a href='https://www.bitrix24.com/'>Bitrix24</a> and creates a new note with a headline, the link to the task and the description."
|
||||||
|
}
|
127
note-from-bitrix-task/note-from-bitrix-task.qml
Normal file
127
note-from-bitrix-task/note-from-bitrix-task.qml
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
import QtQml 2.0
|
||||||
|
import com.qownnotes.noteapi 1.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This script creates a menu item and a button that parses the text that was copied
|
||||||
|
* from a task webpage of the webservice bitrix24 and creates a new note with a headline,
|
||||||
|
* the link to the task and the description
|
||||||
|
*/
|
||||||
|
QtObject {
|
||||||
|
/**
|
||||||
|
* Initializes the custom action
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
// create a menu entry "New Bitrix note" with a button and a freedesktop theme icon
|
||||||
|
script.registerCustomAction("newBitrixTaskNote", "New Bitrix task note", "Bitrix", "task-new");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is invoked when a custom action is triggered
|
||||||
|
* in the menu or via button
|
||||||
|
*
|
||||||
|
* @param identifier string the identifier defined in registerCustomAction
|
||||||
|
*/
|
||||||
|
function customActionInvoked(identifier) {
|
||||||
|
switch (identifier) {
|
||||||
|
// create a new note from a Bitrix task webpage text in the clipboard
|
||||||
|
// like from https://yourname.bitrix24.com/workgroups/group/10/tasks/task/view/150/
|
||||||
|
case "newBitrixTaskNote":
|
||||||
|
// get the text that is currently in the clipboard
|
||||||
|
var html = script.clipboard(true);
|
||||||
|
|
||||||
|
// script.log(html);
|
||||||
|
|
||||||
|
// https://regex101.com is your friend
|
||||||
|
// var headlineRegExp = /<span class="pagetitle-inner".*?>(.+?)<\/span>/im;
|
||||||
|
var headlineRegExp = /<span id="pagetitle".*?>(.+?)<\/?span/im;
|
||||||
|
var headlineMatch = headlineRegExp.exec(html);
|
||||||
|
var headline = headlineMatch !== null ? headlineMatch[1] : "";
|
||||||
|
// remove the "aufgabe" text and all "/"
|
||||||
|
headline = headline.replace("(aufgabe #", "(#").replace(/\s*\//igm, "");
|
||||||
|
|
||||||
|
if (headline == "") {
|
||||||
|
script.informationMessageBox("No Bitrix task headline was found!", "Bitrix task note");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the task id to the headline
|
||||||
|
var taskIdRegExp = /<div class="task-detail-subtitle-status.*?".*?>Aufgabe #(\d+)/im;
|
||||||
|
var taskIdMatch = taskIdRegExp.exec(html);
|
||||||
|
if (taskIdMatch !== null) {
|
||||||
|
headline += " (#" + taskIdMatch[1] + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
var descriptionRegExp = /<div.*? id="task-detail-description".*?>(.+?)<\/div>/im;
|
||||||
|
var descriptionMatch = descriptionRegExp.exec(html);
|
||||||
|
var description = descriptionMatch !== null ? descriptionMatch[1] : "";
|
||||||
|
|
||||||
|
// replace links
|
||||||
|
// description = description.replace(/<a href="(.+?)".*?>(.+?)<\/a>/gim, "[$2]($1)");
|
||||||
|
description = description.replace(/<a href="(.+?)".*?>(.+?)<\/a>/gim, "<$1>");
|
||||||
|
|
||||||
|
// transform html breaks to \n and remove all other tags
|
||||||
|
description = description.replace(/<br.*?>/gim, "\n").replace(/<.+?>/gim, "");
|
||||||
|
|
||||||
|
// var urlRegExp = /<form name="COMMENTS_.+?".*? action="(.+?)" method/im;
|
||||||
|
var urlRegExp = /<a href="(.+?)[\?#].*?" class="main-buttons-item-link"/im;
|
||||||
|
var urlMatch = urlRegExp.exec(html);
|
||||||
|
var url = urlMatch !== null ? urlMatch[1] : "";
|
||||||
|
|
||||||
|
// fallback url parsing
|
||||||
|
if (url == "") {
|
||||||
|
var urlRegExp = /<\/span><a href="(.+?)[\?#].*?" class="task-view-button edit.*?"/im;
|
||||||
|
var urlMatch = urlRegExp.exec(html);
|
||||||
|
var url = urlMatch !== null ? urlMatch[1] : "";
|
||||||
|
|
||||||
|
// we got the edit-url, but we want the view-url
|
||||||
|
url = url.replace("task/edit", "task/view");
|
||||||
|
}
|
||||||
|
|
||||||
|
// script.log("headline");
|
||||||
|
// script.log(headline);
|
||||||
|
// script.log(url);
|
||||||
|
// script.log(descriptionMatch);
|
||||||
|
// script.log(description);
|
||||||
|
// script.log(url);
|
||||||
|
|
||||||
|
// add the headline of the task
|
||||||
|
var text = headline + "\n";
|
||||||
|
|
||||||
|
// add "=" characters so that the headline is really a headline
|
||||||
|
for (var i = 0; i < headline.length; i++) {
|
||||||
|
text += "=";
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the url to the task
|
||||||
|
if (url != "") {
|
||||||
|
text += "\n\n- <" + url + ">";
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the description of the task
|
||||||
|
if (description != "") {
|
||||||
|
text += "\n\n" + description;
|
||||||
|
}
|
||||||
|
|
||||||
|
text = text.replace(/>/gim, ">").replace(/</gim, "<");
|
||||||
|
|
||||||
|
// add a date headline
|
||||||
|
var m = new Date();
|
||||||
|
var dateString =
|
||||||
|
("0" + m.getDate()).slice(-2) + "." +
|
||||||
|
("0" + (m.getMonth()+1)).slice(-2) + "." +
|
||||||
|
m.getFullYear();
|
||||||
|
text += "\n\n## " + dateString + "\n\n";
|
||||||
|
|
||||||
|
// create a new note
|
||||||
|
script.createNote(text);
|
||||||
|
|
||||||
|
// tag the current note
|
||||||
|
script.tagCurrentNote("todo");
|
||||||
|
|
||||||
|
// workaround because the parsers don't seem to work every time
|
||||||
|
script.reloadScriptingEngine();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
note-from-jira-issue/info.json
Normal file
9
note-from-jira-issue/info.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "Note from Jira issue",
|
||||||
|
"identifier": "note-from-jira-issue",
|
||||||
|
"script": "note-from-jira-issue.qml",
|
||||||
|
"authors": ["@pbek"],
|
||||||
|
"version": "0.0.1",
|
||||||
|
"minAppVersion": "17.05.6",
|
||||||
|
"description" : "This script creates a menu item and a button that parses the text that was copied from an issue webpage of <a href='https://www.atlassian.com/software/jira'>Jira</a> and creates a new note with a headline, the link to the issue and the description."
|
||||||
|
}
|
108
note-from-jira-issue/note-from-jira-issue.qml
Normal file
108
note-from-jira-issue/note-from-jira-issue.qml
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
import QtQml 2.0
|
||||||
|
import com.qownnotes.noteapi 1.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This script creates a menu item and a button that parses the text that was copied
|
||||||
|
* from an issue webpage of Jira and creates a new note with a headline,
|
||||||
|
* the link to the issue and the description
|
||||||
|
*/
|
||||||
|
QtObject {
|
||||||
|
/**
|
||||||
|
* Initializes the custom action
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
// create a menu entry "New Jira note" with a button and a freedesktop theme icon
|
||||||
|
script.registerCustomAction("newJiraIssueNote", "New Jira issue note", "Jira", "task-new");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is invoked when a custom action is triggered
|
||||||
|
* in the menu or via button
|
||||||
|
*
|
||||||
|
* @param identifier string the identifier defined in registerCustomAction
|
||||||
|
*/
|
||||||
|
function customActionInvoked(identifier) {
|
||||||
|
if (identifier != "newJiraIssueNote") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a new note from a Jira issue webpage text in the clipboard
|
||||||
|
// like from https://jira.madsack-online.de/browse/EZ-127185
|
||||||
|
|
||||||
|
// get the text that is currently in the clipboard
|
||||||
|
var html = script.clipboard(true);
|
||||||
|
|
||||||
|
// script.log(html);
|
||||||
|
|
||||||
|
// https://regex101.com is your friend
|
||||||
|
var headlineRegExp = /<h1 id="summary-val".*?>(.+?)<\/?h1>/im;
|
||||||
|
var headlineMatch = headlineRegExp.exec(html);
|
||||||
|
var headline = headlineMatch !== null ? headlineMatch[1] : "";
|
||||||
|
// remove all /, " and '
|
||||||
|
headline = headline.replace(/\s*\//igm, "").replace(/["']/igm, "").replace(/<.+?>/igm, "");
|
||||||
|
|
||||||
|
if (headline == "") {
|
||||||
|
script.informationMessageBox("No Jira issue headline was found!", "Jira issue note");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the issue id to the headline
|
||||||
|
var issueIdRegExp = /<a class="issue-link" data-issue-key="([^"]+)" href="(http[^"]+\/browse\/[^"]+)" id="key-val"/im;
|
||||||
|
var issueIdMatch = issueIdRegExp.exec(html);
|
||||||
|
var url;
|
||||||
|
if (issueIdMatch !== null) {
|
||||||
|
headline += " (" + issueIdMatch[1] + ")";
|
||||||
|
url = issueIdMatch[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
var descriptionRegExp = /<div.*? id="description-val".*?>(.+?)<\/div>/im;
|
||||||
|
var descriptionMatch = descriptionRegExp.exec(html);
|
||||||
|
var description = descriptionMatch !== null ? descriptionMatch[1] : "";
|
||||||
|
|
||||||
|
// replace links
|
||||||
|
// description = description.replace(/<a href="(.+?)".*?>(.+?)<\/a>/gim, "[$2]($1)");
|
||||||
|
description = description.replace(/<a href="(.+?)".*?>(.+?)<\/a>/gim, "<$1>");
|
||||||
|
|
||||||
|
// transform html breaks to \n, <p> into \n\n and remove all other tags
|
||||||
|
description = description.replace(/<br.*?>/gim, "\n").replace(/<\/p>/gim, "\n\n").replace(/<.+?>/gim, "").trim();
|
||||||
|
|
||||||
|
// add the headline of the issue
|
||||||
|
var text = headline + "\n";
|
||||||
|
|
||||||
|
// add "=" characters so that the headline is really a headline
|
||||||
|
for (var i = 0; i < headline.length; i++) {
|
||||||
|
text += "=";
|
||||||
|
}
|
||||||
|
|
||||||
|
text += "\n\n";
|
||||||
|
|
||||||
|
// add the url to the issue
|
||||||
|
if (url != "") {
|
||||||
|
text += "- <" + url + ">\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the description of the issue
|
||||||
|
if (description != "") {
|
||||||
|
text += description + "\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
text = text.replace(/>/gim, ">").replace(/</gim, "<");
|
||||||
|
|
||||||
|
// add a date headline
|
||||||
|
var m = new Date();
|
||||||
|
var dateString =
|
||||||
|
("0" + m.getDate()).slice(-2) + "." +
|
||||||
|
("0" + (m.getMonth()+1)).slice(-2) + "." +
|
||||||
|
m.getFullYear();
|
||||||
|
text += "\n\n## " + dateString + "\n\n";
|
||||||
|
|
||||||
|
// create a new note
|
||||||
|
script.createNote(text);
|
||||||
|
|
||||||
|
// tag the current note
|
||||||
|
script.tagCurrentNote("todo");
|
||||||
|
|
||||||
|
// workaround because the parsers don't seem to work every time
|
||||||
|
// script.reloadScriptingEngine();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue