hi can you check over what i've tried to do with the multiple favorites? I can't seem to get it working...
var title_regexp = [/^.+- Wikipedia, the free encyclopedia$/, /^.+- Stack Overflow$/, /^.+- W3Schools$/];
var addr_regexp = [/^\w+\.wikipedia\.org\/.*$/, /^stackoverflow\.com\/.*$/, /^www\.w3schools\.com\/.*$/];
var mark_style = 'background-color: #CCFF99 !important; padding: 0.5em; -moz-border-radius: 0.5em';
var match_pattern = [3,3,3];
and the rest is untouched.
thank you for your help
the original document is at http://userscripts.org/scripts/show/55641
According to the docs and code for that script, match_pattern should be an integer, not an array. :
var match_pattern = 3;
Related
I have two arrays like below and implemented the iterations using old for loop approach. However, how can I get the same in forEach().
var questions =['your name', 'SkillSet', 'exp']
var answers =['King', 'Nodejs', '5']
for(let i = 0; i<questions.length; i++){
htmlobj += '<tr><th>'+questions[i]+'</th></tr>'
htmlobj += '<tr><th>'+answers[i]+'</th></tr>'
}
I pretty much consider a .forEach() loop to be obsolete these days because a for loop is so much more flexible. With modern Javascript, you can use for/of and still get value and index:
const questions =['your name', 'SkillSet', 'exp']
const answers =['King', 'Nodejs', '5']
let htmlobj = "";
for (const [index, question] of questions.entries()) {
htmlobj += `<tr><th>${question}</th></tr><tr><th>${answers[index]}</th></tr>`;
}
console.log(htmlobj);
While the additional flow control advantages of a for loop aren't being used here, they are very useful in many other circumstances and the regular for loop doesn't incur the function overhead of calling a callback function for every iteration of the loop.
And, if you want one row for each question and answer, you would need to change the HTML like this:
const questions =['Your Name', 'SkillSet', 'Exp']
const answers =['King', 'Nodejs', '5']
let htmlobj = "";
for (const [index, question] of questions.entries()) {
htmlobj += `<tr><th>${question}</th><th>${answers[index]}</th></tr>`;
}
document.getElementById("result").innerHTML = htmlobj;
table {
border-collapse: collapse;
}
th {
text-align: left;
border-bottom: 1px solid;
margin: 0;
padding: 10px;
}
<table id=result></table>
let htmlobj = ""
questions.forEach((el, index) => {
htmlobj += '<tr><th>'+el+'</th></tr>'
htmlobj += '<tr><th>'+answers[index]+'</th></tr>'
})
I am trying to export my table into excel sheet here I am generating my html table using json data dynamically.
I am using this code to generate my table in angular:
var table = document.createElement("TABLE") as HTMLTableElement;
var row,header,cell1, cell2;
var data = chart.options.data;
// table.style.border = "1px solid #000";
header = table.createTHead();
row = header.insertRow(0);
table.setAttribute("id", "myId");
cell1 = row.insertCell(0);
cell2 = row.insertCell(1);
// cell1.style.border = "1px solid #000";
// cell2.style.border = "1px solid #000";
cell1.innerHTML = "<strong>Districts</strong>";
cell2.innerHTML = "<b>"+rain_fall_type+"_Value</b>";
for(var i = 0; i < data.length; i++){
for(var j = 0; j< data[i].dataPoints.length; j++){
// console.log(data[i].dataPoints[j]);
// console.log(data[i].dataPoints[j].label);
row = table.insertRow(1);
cell1 = row.insertCell(0);
cell2 = row.insertCell(1);
// cell1.style.border = "1px solid #000";
// cell2.style.border = "1px solid #000";
cell1.innerHTML = "<strong>"+data[i].dataPoints[j].label+"</strong>";
cell2.innerHTML = data[i].dataPoints[j].y;
}
}
// document.getElementById("chartContainer").innerHTML = "<h1>"+rain_fall_type+" "+year+"</h2>";
document.getElementById("chartContainer").appendChild(table);
This is generating a table and a values I am trying to use : https://www.npmjs.com/package/tableexport this library to export my table. When I am adding html table and run this code:
var n = new TableExport(document.getElementsByTagName("table"));
inside ngoninit I can see three buttons and all of them work fine but. When I am generating a dynamic table using above code I don't see any button to export.
I have added a button and on that click I am using this:
myEvent(event) {
var n = new TableExport(document.getElementsByTagName("table"));
}
When I click on this button I can see all three buttons to export but none of them is clickable. Is there any way I can make it work with dynamic html table.
you are missing the (click)="myEvent()" in your buttons, for example
<button (click)="myEvent($event)" type="button" tableexport-id="5bf287e5-xlsx" class="button-default xlsx">Export to xlsx</button>
But also, in myEvent you define
var table = new TableExport(document.getElementsByTagName("table"));
Shouldn't it be, just to be sure you grab the correct table
var table = new TableExport(document.getElementById("myId"));
In Angular you should be using Template reference variables ( #myTable ) and getting a reference to them in the controller with #ViewChild('myTable')
I am using node/npm blessed to create a screen to monitor a particular application and I want the monitor tool to look/act like linux top. The problem I have, which I think is relatively simple (but I cant find the answer anywhere), is to have blessed clear the screen at startup as well as at particular points based upon user input.
Right now I can use blessed to paint the screen properly (sample program below), but the problem is I need the screen to be cleared at startup (right now the first line of output just appends right after you start up the program):
var blessed = require('blessed');
var screen = blessed.screen(),
body = blessed.box({
top: 0,
left: 0,
width: '100%',
height: '100%',
tags: true
});
var items = [];
screen.append(body);
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
});
function log(text) {
items.push(text);
var MAX = 10;
if( items.length > MAX+1 ){
items.shift();
}
for (var i=1; i<MAX; i++){
body.setLine(i, items[i]);
}
screen.render();
}
function status(text) {
body.setLine(0, text );
screen.render();
}
var counter = 1;
setInterval(function() {
status((new Date()).toISOString());
log('Line number: ' + (counter++));
}, 1000);
For completeness, the solution to this question is provided below, and is very simple. To clear the screen, issue the following code at the start of the program:
screen.render();
The sample program that I referenced in the original post can be modified as follows and now works:
var blessed = require('blessed');
var screen = blessed.screen(),
body = blessed.box({
top: 0,
left: 0,
width: '100%',
height: '100%',
tags: true
});
// The following line clears the screen
screen.render();
:
:
My Gnome Shell extension has a folder 'icons' and there is an icon file called 'MyIcon.png' inside. I want to take it as a parameter to an St.Icon object.
let icon = new St.Icon({ /* I need what to code here*/ });
Thanks for any help.
Selcuk.
Here is a solution for GnomeShell v3.8.4:
const St = imports.gi.St;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Gio = imports.gi.Gio;
let gicon = Gio.icon_new_for_string(Me.path + "/icons/my_icon.png");
icon = new St.Icon({ gicon });
Stumbled upon the very same problem yesterday.
You have to do two things:
Step 1: add this code to you "stylesheet.css"
.your-icon-name {
background-image: url("icons/MyIcon.png");
background-size: 20px;
height: 20px;
width: 20px;
}
'background-size', 'height' and 'width' are just there to prescale the image, they can be left out to keep the original size.
Step 2: Write this in your .js file:
let icon = new St.Icon({style_class: 'your-icon-name'});
Here is an example of how to do it:
_getIconImage: function() {
let icon_file = this._path + "/icons/icon.png";
let file = Gio.file_new_for_path(icon_file);
let icon_uri = file.get_uri();
return St.TextureCache.get_default().load_uri_async(icon_uri, 64, 64);
},
myIcon = _getIconImage();
For anyone wanting to add their extension's icon/ (or images/, etc.) sub directory to the search path in order to use CSS styles here is what is working for me:
function init(metadata) {
// ...
let theme = imports.gi.Gtk.IconTheme.get_default();
theme.append_search_path(metadata.path + "/icons");
// ...
}
I need alittle help with getting a script that will take param from the orginal link and re-write them into a new link. I guess it should be pretty easy but I'm a noob still when it comes to this.
Here is the orginal HTML code for 1 link. (should be replaced globaly on the page. image1.jpg, image2.jpg etc.)
<div align="center"><img src="/preview/image1.jpg" width="128" height="128" border="0" style="border: 0px black solid;" /></div>
This should be done global on all the links that contain the imagepath "/preview/"
Thanks to Brock Adams I kinda understand how to get the param values with this code but I still don't really get it how to re-write all the links in a page.
var searchableStr = document.URL + '&';
var value1 = searchableStr.match (/[\?\&]id=([^\&\#]+)[\&\#]/i) [1];
var value2 = searchableStr.match (/[\?\&]connect=([^\&\#]+)[\&\#]/i) [1];
and then rewrite the links with "newlink"
var domain = searchableStr.match (/\/\/([w\.]*[^\/]+)/i) [1];
var newlink = '//' + domain + '/' + value1 + '/data/' + value2 + '.ext';
If someone could be so nice to help me setup an example greasemonkey script I would be very greatful for it.
OK, This is a fairly common task and I don't see any previous, Stack Overflow questions like it -- at least in a 2 minute search.
So, here's a script that should do what you want, based on the information provided...
// ==UserScript==
// #name Site_X, image relinker.
// #namespace StackOverflow
// #description Rewrites the preview links to ???
// #include http://Site_X.com/*
// #include http://www.Site_X.com/*
// #include https://Site_X.com/*
// #include https://www.Site_X.com/*
// ==/UserScript==
function LocalMain () {
/*--- Get all the images that have /preview/ in their path.
*/
var aPreviewImages = document.evaluate (
"//img[contains (#src, '/preview/')]",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null
);
var iNumImages = aPreviewImages.snapshotLength;
GM_log (iNumImages + ' preview images found.');
/*--- Rewrite the parent links to our new specifications.
Note, all the target links are of the form:
<a href="/index.php?Submit=ok&seson=b1e4&connect=127.0.0.1&id=13033&name=on">
<img src="/preview/image1.jpg" width="128" height="128" border="0" style="border: 0px black solid;" />
</a>
The desired rewrite changes the link to this form:
<a href="{current page's domain}/{id-value}/data/{connect-value}.ext">
*/
for (var iLinkIdx=0; iLinkIdx < iNumImages; iLinkIdx++) {
var zThisImage = aPreviewImages.snapshotItem (iLinkIdx);
var zParentLink = zThisImage.parentNode;
//--- Get the key href parameters.
var sIdValue = sGetUrlParamValue (zParentLink, 'id');
if (!sIdValue) continue; //-- Oopsie, this link was a malformed.
var sConnectValue = sGetUrlParamValue (zParentLink, 'connect');
if (!sConnectValue) continue;
//--- Get the current page's domain. (Or just use a relative link.)
var sPageDomain = document.URL.match (/\/\/([w\.]*[^\/]+)/i) [1];
//--- Generate the desired link value.
var sDesiredLink = 'http://' + sPageDomain + '/' + sIdValue + '/data/' + sConnectValue + '.ext';
//--- Rewrite the target link.
zParentLink.href = sDesiredLink;
}
}
function sGetUrlParamValue (zTargLink, sParamName) {
var zRegEx = eval ('/[\?\&]' + sParamName + '=([^\&\#]+)[\&\#]/i');
var aMatch = (zTargLink.href + '&').match (zRegEx);
if (aMatch)
return decodeURI (aMatch[1]);
else
return null;
}
window.addEventListener ("load", LocalMain, false);