Greasemonkey onmousemove script - greasemonkey

I have a UserScript which should remove all images of a certain class on the first mousemove-event.
Being pretty new in writing Greasemonkey-scripts, okay this is my first script, I think there is just something small missing.
// ==UserScript==
// #name aname
// #namespace anamespace
// #description adescription
// #include http://www.google.com/search*
// #include http://www.google.com/webhp*
// #include http://www.google.com/#*
// #include http://www.google.com/
// ==/UserScript==
var removeTags = function () {
var allHTMLTags = window.document.getElementsByTagName("*");
for (i=0; i < allHTMLTags.length; i++) {
if (allHTMLTags[i].className == "l sb-l") {
allHTMLTags[i].style.display='none';
}
}
};
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = removeTags;
Thanks for your help!

Try addEventListener
window.addEventListener('mousemove',removeTags,false);

Related

how to fix problem with swap chain creation

im learning directx im working on initializing direct3d in my application and all of my HRESULTS are returning S_OK which is a success return code except the last one which involved swap chain creation i have the debug layer enabled so im getting a warning error in the Output Log that says 'OurDevice' could be 0... (OurDevice is the pointer name to my ID3D11Device).. after many hours of scanning through Microsoft Docs and checking and rechecking all my code i cant seem to find out the issue does anyone have a clue ?
#include "dx3dmanager.h"
#include "Core.h"
#include <Windows.h>
#include <d3d11.h>
#include <d3d11_1.h>
#include <d3d11_2.h>
#include <DirectXMath.h>
#include <dxgi.h>
dx3dmanager::dx3dmanager()
{
}
dx3dmanager::~dx3dmanager()
{
}
// this method intitializes the Direct3d version 11 API this
initialization method is subject to change with new versions /*
void dx3dmanager::initialize3d(HWND MainWindow)
{
// declarations for Direct3D feature levels ours will include
versions 11-12 unless changed /*
//declarations for our device(GPU) and device context /*
UINT creationflags = D3D11_CREATE_DEVICE_DEBUG;
ID3D11Device* OurDevice;
ID3D11DeviceContext* IDeviceContext;
D3D_FEATURE_LEVEL featurelevels[2] =
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_11_1
};
HRESULT CreateDev;
switch (CreateDev) {
case S_OK: {
MessageBeep(0xFFFFFFFF);
}
}
// checks multisampling quality
HRESULT checkmxquality;
UINT m4xMsaaQuality;
DXGI_FORMAT dxgi_format = DXGI_FORMAT_R8G8B8A8_UNORM;
checkmxquality = OurDevice->CheckMultisampleQualityLevels(dxgi_format, 4, &m4xMsaaQuality);
assert(m4xMsaaQuality > 0);
switch (checkmxquality) {
case S_OK: {
MessageBeep(0xFFFFFFFF);
}
break;
}
// descriptions for rendering structs IE: sampling, format, and swap
chain /*
DXGI_SAMPLE_DESC sampdesc;
sampdesc.Count = 1;
sampdesc.Quality = 0;
DXGI_MODE_DESC1 dxmode;
dxmode.Width = 125;
dxmode.Height = 125;
dxmode.Format = dxgi_format;
dxmode.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
dxmode.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
dxmode.RefreshRate.Numerator = 60;
dxmode.RefreshRate.Denominator = 1;
dxmode.Stereo = false;
DXGI_SWAP_CHAIN_DESC1 chaindesc;
chaindesc.Width = 0;
chaindesc.Height = 0;
chaindesc.Format = dxgi_format;
chaindesc.Stereo = false;
chaindesc.SampleDesc = sampdesc;
chaindesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
chaindesc.BufferCount = 3;
chaindesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
chaindesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH|
DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE| DXGI_SWAP_CHAIN_FLAG_DISPLAY_ONLY;
chaindesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
chaindesc.Scaling = DXGI_SCALING_STRETCH;
//-------------------------------------------------------------------
-------------------------------/*
// this is our DXGI interface (DXGI is not a part of direct3d it is a
seperate API (COM) /*
IDXGIDevice* dxgiDevice = nullptr;
CreateDev = OurDevice->QueryInterface(__uuidof(IDXGIDevice),
(void**)& dxgiDevice);
if (SUCCEEDED(CreateDev)) {
MessageBeep(0xFFFFFFFF);
}
IDXGIAdapter* dxgiadapter = nullptr;
CreateDev = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&
dxgiadapter);
if (SUCCEEDED(CreateDev)) {
MessageBeep(0xFFFFFFFF);
}
IDXGIFactory2* factory;
CreateDev = dxgiadapter->GetParent(__uuidof(IDXGIFactory), (void**)&
factory);
if (SUCCEEDED(CreateDev)) {
MessageBeep(0xFFFFFFFF);
}
IDXGISwapChain1* mSwapChain;
CreateDev = factory->CreateSwapChainForHwnd(OurDevice, MainWindow,
&chaindesc, NULL, NULL, &mSwapChain);
if (FAILED(CreateDev)) {
MessageBeep(0xFFFFFFFF);
}
//-------------------------------------------------------------------
-------------------------------/*
If you enable DXGI debugging as well as using D3D11_CREATE_DEVICE_DEBUG, then you will get output messages in the debug window that tells you problems that result in failed error codes.
Even with just the Direct3D 11 debugging enabled, you get:
D3D11 ERROR: ID3D11Device::CreateTexture2D1: D3D11_RESOURCE_MISC_GDI_COMPATIBLE
requires a B8G8R8A8 format.
[ STATE_CREATION ERROR #103: CREATETEXTURE2D_INVALIDMISCFLAGS]
So your problem is very simple and easy to fix: Change dxgi_format to DXGI_FORMAT_B8G8R8A8_UNORM
See Anatomy of Direct3D 11 Create Device as well as Direct3D Game Visual Studio templates

Invoke JS object constructor from C when object constructor defined inside js module

Using Duktape over microchip 32, everything running well.
BTW, when using module loading( which is also working like a charm), i'm facing a kind of pattern question.
lets me explains:
I define a constructor inside a js module
var MyObject = function(a){
this.a = a;
}
...
module.exports = MyObject;
now i'm using this module inside anothers program.
const toto = require('myobject');
var dummy = new toto('1');
Still working.
Question is : HOW do i call the MyObject constructor from C without knowing the name ('toto') affected when requiring the module (which is basically user related).
duk_push_global_object(ctx); // [global]
duk_bool_t res = duk_get_prop_string(ctx, -1, "toto"); // [global toto]
duk_push_string(ctx, "1"); // [global toto param0]
duk_new(ctx, 3); // [global result]
duk_remove(ctx, -2); // [result]
I whish to use 'MyObject' instead without constraint the developper to declare
const MyObject = require('myobject');
I know i can declare the object entirely in c to avoid this, but maybe one of you has already a best practice..
It's seem also that duktape do NOT define access to the global scope into module like nodejs does. (I can also add this to duk_module_node.c, but at last solution..)
Thanks for your comments.
After trying different pattern, i decided the most direct solution is to add a 'global' parameter as the module wrapper (similar to nodejs).
here the small code modification in duk_module_node.c
#ifdef ADD_GLOBAL_TO_MODULES
duk_push_string(ctx, "(function(exports,require,module,__filename,__dirname,global){");
#else
duk_push_string(ctx, "(function(exports,require,module,__filename,__dirname){");
#endif // ADD_GLOBAL_TO_MODULES
duk_dup(ctx, -2); /* source */
duk_push_string(ctx, "})");
duk_concat(ctx, 3);
/* [ ... module source func_src ] */
(void) duk_get_prop_string(ctx, -3, "filename");
duk_compile(ctx, DUK_COMPILE_EVAL);
duk_call(ctx, 0);
/* [ ... module source func ] */
/* Set name for the wrapper function. */
duk_push_string(ctx, "name");
duk_push_string(ctx, "main");
duk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_FORCE);
/* call the function wrapper */
(void) duk_get_prop_string(ctx, -3, "exports"); /* exports */
(void) duk_get_prop_string(ctx, -4, "require"); /* require */
duk_dup(ctx, -5); /* module */
(void) duk_get_prop_string(ctx, -6, "filename"); /* __filename */
duk_push_undefined(ctx); /* __dirname */
#ifdef ADD_GLOBAL_TO_MODULES
duk_push_global_object(ctx); /* global */
duk_call(ctx, 6);
#else
duk_call(ctx, 5);
#endif
defining ADD_GLOBAL_TO_MODULES into duk_module_node.h
#define ADD_GLOBAL_TO_MODULES
you can now use js code in a module in the following way:
var _static = function (value, timestamp, quality, index) {
this.value = value;
this.timestamp = timestamp || new Date().getTime();
this.quality = quality || _static.Quality.GOOD;
this.index = index || _static.INDEX_NONE;
}
_static.Quality = { GOOD: 0, UNCERTAIN: 1, BAD: 2, UNKNOWN: 3 };
_static.INDEX_NONE = -1;
_static.prototype = (function () {
var _proto = _static.prototype;
return _proto;
})();
module.exports = _static ;
if(global) global.DatapointSample = global.DatapointSample || _static ;
you can now use
new DataPointSample()
anywhere or call it from c knowing the name.
I know this oblige to maintain both c and js naming BUT in a microcontroller firmware it's highly acceptable.
Regards.

PCL 1.6: generate pcd files from each frame of a oni file

I need to process each frame of a ONI file. For now I want just to save each frame of a file.oni in file.pcd. I follow this code but it works only with PCL 1.7 and I'm using v1.6.
So I changed a bit the code in this manner
#include <pcl/io/openni_grabber.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/oni_grabber.h>
#include <pcl/io/pcd_io.h>
#include <vector>
int i = 0;
char buf[4096];
class SimpleOpenNIViewer
{
public:
SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}
void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
{
//if (!viewer.wasStopped())
//{
// viewer.showCloud (cloud);
pcl::PCDWriter w;
sprintf (buf, "frame_%06d.pcd", i);
w.writeBinaryCompressed (buf, *cloud);
PCL_INFO ("Wrote a cloud with %zu (%ux%u) points in %s.\n",cloud->size (), cloud->width, cloud->height, buf);
++i;
//}
}
void run ()
{
pcl::Grabber* interface = new pcl::OpenNIGrabber("file.oni");
boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f = boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);
interface->registerCallback (f);
interface->start ();
while (!viewer.wasStopped())
{
boost::this_thread::sleep (boost::posix_time::seconds (1));
}
PCL_INFO ("Successfully processed %d frames.\n", i);
interface->stop ();
}
pcl::visualization::CloudViewer viewer;
};
int main ()
{
SimpleOpenNIViewer v;
v.run ();
return 0;
}
But it crash when I run it. Why?
I solved my problem about getting each frame from a ONI file. I need to use the ONIGrabber function set in the trigger mode.
This is the modified code:
#include <pcl/io/openni_grabber.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/oni_grabber.h>
#include <pcl/io/pcd_io.h>
#include <vector>
class SimpleOpenNIViewer
{
public:
SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}
void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
{
//if (!viewer.wasStopped())
//{
// viewer.showCloud (cloud);
pcl::PCDWriter w;
sprintf (buf, "frame_%06d.pcd", i);
w.writeBinaryCompressed (buf, *cloud);
PCL_INFO ("Wrote a cloud with %zu (%ux%u) points in %s.\n",cloud->size (),
cloud->width, cloud->height, buf);
++i;
//}
}
void run ()
{
pcl::Grabber* interface = new pcl::ONIGrabber("file.oni",false,false); //set for trigger
boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f = boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);
interface->registerCallback (f);
interface->start ();
while (!viewer.wasStopped())
{
interface->start()//to update each frame from the oni file
boost::this_thread::sleep (boost::posix_time::seconds (1));
}
PCL_INFO ("Successfully processed %d frames.\n", i);
interface->stop ();
}
pcl::visualization::CloudViewer viewer;
};
int main ()
{
SimpleOpenNIViewer v;
v.run ();
return 0;
}`

Display html page using mongoose server

I am trying to display an html page in mongoose server
I tried using the below code which is not working can any one tell me what is the issue in that code.
#include <stdio.h>
#include <string.h>
#include "mongoose/mongoose.h"
static int begin_request_handler(struct mg_connection *conn) {
const struct mg_request_info *request_info = mg_get_request_info(conn);
static const char *login_url = "/index.html";
mg_printf(conn, "HTTP/1.1 200 OK\r\n"
"Content-Type: text/html\r\n"
"Location: %s\r\n\r\n", login_url);
return 1;
}
int main(void) {
struct mg_context *ctx;
struct mg_callbacks callbacks;
const char *options[] = { "listening_ports", "8080", NULL };
memset(&callbacks, 0, sizeof(callbacks));
callbacks.begin_request = begin_request_handler;
ctx = mg_start(&callbacks, NULL, options);
getchar();
mg_stop(ctx);
return 0;
}
What are you trying to accomplish? In the options[] add a "document_root" (you always need a document_root in your options for mongoose), place your index.html in that directory, and remove the callbacks from mg_start. And mongoose will serve your index.html automatically.

Qt - how to save my QTableView as a Excel File?

Can anyone plz help me, how to save my QtableView as a Excel File. I have a QTableView and a QPushButton (Save Button). If i enter the values in my QtableView and if i click the Save Buttton the QTableView items should be saved as Excel File. Plz Help me. Thanks..
Have a look at this thread My-approach-to-export-QTableView-data-to-a-Microsoft-Excel-file. I got this link by asking Google for: QTableView save. For the solution there you need a Qt with ODBC enabled which is not the default.
You can also study the fine documentation that contains e.g. an Address Book Example that includes a writeToFile function. You can start from there and search e.g. for information about the CSV format.
this link worked for me :
http://www.qtcn.org/bbs/simple/?t47265.html
1-you should also use below code in .pro file.
QT += sql
2-you should use #include "exportexcelobject.h" in your file that wanna export to excel.
See the code sample:
ExcelExportHelper.h
#ifndef EXCELHELPER_H
#define EXCELHELPER_H
#include <ActiveQt/qaxobject.h>
#include <ActiveQt/qaxbase.h>
#include <QString>
//Expected in .pro file: QT += axcontainer
//Application must be of UI type for ActiveX work.
class ExcelExportHelper
{
public:
ExcelExportHelper(const ExcelExportHelper& other) = delete;
ExcelExportHelper& operator=(const ExcelExportHelper& other) = delete;
ExcelExportHelper(bool closeExcelOnExit = false);
void SetCellValue(int lineIndex, int columnIndex, const QString& value);
void SaveAs(const QString& fileName);
~ExcelExportHelper();
private:
QAxObject* m_excelApplication;
QAxObject* m_workbooks;
QAxObject* m_workbook;
QAxObject* m_sheets;
QAxObject* m_sheet;
bool m_closeExcelOnExit;
};
#endif // EXCELHELPER_H
ExcelExportHelper.cpp
#include <ActiveQt/qaxobject.h>
#include <ActiveQt/qaxbase.h>
#include <QString>
#include <QFile>
#include <stdexcept>
using namespace std;
#include "ExcelExportHelper.h"
ExcelExportHelper::ExcelExportHelper(bool closeExcelOnExit)
{
m_closeExcelOnExit = closeExcelOnExit;
m_excelApplication = nullptr;
m_sheet = nullptr;
m_sheets = nullptr;
m_workbook = nullptr;
m_workbooks = nullptr;
m_excelApplication = nullptr;
m_excelApplication = new QAxObject( "Excel.Application", 0 );//{00024500-0000-0000-C000-000000000046}
if (m_excelApplication == nullptr)
throw invalid_argument("Failed to initialize interop with Excel (probably Excel is not installed)");
m_excelApplication->dynamicCall( "SetVisible(bool)", false ); // hide excel
m_excelApplication->setProperty( "DisplayAlerts", 0); // disable alerts
m_workbooks = m_excelApplication->querySubObject( "Workbooks" );
m_workbook = m_workbooks->querySubObject( "Add" );
m_sheets = m_workbook->querySubObject( "Worksheets" );
m_sheet = m_sheets->querySubObject( "Add" );
}
void ExcelExportHelper::SetCellValue(int lineIndex, int columnIndex, const QString& value)
{
QAxObject *cell = m_sheet->querySubObject("Cells(int,int)", lineIndex, columnIndex);
cell->setProperty("Value",value);
delete cell;
}
void ExcelExportHelper::SaveAs(const QString& fileName)
{
if (fileName == "")
throw invalid_argument("'fileName' is empty!");
if (fileName.contains("/"))
throw invalid_argument("'/' character in 'fileName' is not supported by excel!");
if (QFile::exists(fileName))
{
if (!QFile::remove(fileName))
{
throw new exception(QString("Failed to remove file '%1'").arg(fileName).toStdString().c_str());
}
}
m_workbook->dynamicCall("SaveAs (const QString&)", fileName);
}
ExcelExportHelper::~ExcelExportHelper()
{
if (m_excelApplication != nullptr)
{
if (!m_closeExcelOnExit)
{
m_excelApplication->setProperty("DisplayAlerts", 1);
m_excelApplication->dynamicCall("SetVisible(bool)", true );
}
if (m_workbook != nullptr && m_closeExcelOnExit)
{
m_workbook->dynamicCall("Close (Boolean)", true);
m_excelApplication->dynamicCall("Quit (void)");
}
}
delete m_sheet;
delete m_sheets;
delete m_workbook;
delete m_workbooks;
delete m_excelApplication;
}
Usage:
try
{
const QString fileName = "g:\\temp\\kaka2.xlsx";
ExcelExportHelper helper;
helper.SetCellValue(1,1,"Test-11");
helper.SetCellValue(1,2,"Test-12");
helper.SaveAs(fileName);
}
catch (const exception& e)
{
QMessageBox::critical(this, "Error - Demo", e.what());
}

Resources