Building an add-on to hide a <div> block on an HTML page - firefox

There's a webpage with something annoying on it which I'd like to hide every time I visit it. I thought a good way to do this would be to make an add-on for Firefox.
I've never done this before, and came across the web-based Firefox add-on builder. I'm not too sure where to go from here though. I know it should be quite easy to do this though. I suppose all I need to do is check if a block with a certain id is used on a website, and if it is, then delete/hide it from my view.
Is that the best way to do about this? If not, what do you suggest? If so, can you give me any tips to help me accomplish this?

Right, I got it:
Using just a standalone Firefox Add-On use the following code:
exports.main = function() {
var pageMod = require("page-mod");
pageMod.PageMod({
include: "*.ca",
contentScriptWhen: 'end',
contentScript: 'document.getElementById("DIVID").style.visibility="hidden";'
});
};
Just replace DIVID with whatever you want.
Similarly, in Greasemonkey, just add this to the script:
document.getElementById('DIVID').style.visibility='hidden';
The only reason I didn't want to use Greasemonkey is that it isn't as easy to share. But it's convenience can't be beat!

Install the latest FF
Install the latest AdBlock Plus
Go to the website right click on specific element and then Inspect Element(Q)
Right bottom corner there is Hide with ABP(AdBlock Plus) button, click on it, then Add Element Hiding Rule

You can just use GreaseMonkey which is a very useful plugin for firefox. You can write your own script in JavaScript which operates on the page.
However, chances are that someone might have already written a script for the site in question that you can install from the http://userscripts.org/ repository.

In well-formed HTML, any particular value for the id attribute should occur at most once in a document. If your mission is to seek and destroy a recurring phenomenon, it might be labeled (if at all) with a class. This is the case with Twitter's "promoted tweets", for example.
var promotedTweets = document.getElementsByClassName("promoted-tweet");
for (k=0; k<promotedTweets.length; k++) {
promotedTweets[k].parentNode.removeChild(promotedTweets[k]);
}

Wouldn't Adblock Plus do the trick here? You can feed it an element hiding rule (based on the class or ID attribute) on any given website, if I recall correctly.

I used the up-and-coming jpm tool to write this, and incorporated the suggestions here. It is specifically for filtering certain div tags here on StackOverflow—how fitting. The code and the xpi add-on file is at Github.

An alternative in Firefox is to create a userContent.css file and add css which hides the div.
See https://superuser.com/a/319322/ and note the comment which points out that "Starting with Firefox 69, you need to set the toolkit.legacyUserProfileCustomizations.stylesheets preference to true".

Related

One mouse over Paragraph change in Article

I wanted to have a feature in my Jommla based application, that when ever a user brings the mouse over a particular paragraph in article the color of text should change. so that the paragraph looks more prominent on the screen.
I want this thing to be dynamic. Just wanted to know which is the best place to do that. Where in the Joomla the article parsing takes place ?. If I am lucky is there any plugin that can help achieve that ? Kindly let me know
You can make a slight modification to Trev's solution and make it work without having to change any articles.
.contentpaneopen p:hover {color:#ff0000;}
By default, Joomla assigns the contentpaneopen class to articles, this would produce the effect on all P tags that are children of that class.
By far the easiest thing to do would be to add a style to paragraph in question in your article and then add an appropriate hover rule in the css, e.g.
<p class="highlight>some text in here</p>
and
p.highlight:hover
{
color: #ff0000;
}
Just tried it here and it worked for me on the last paragraph:
http://thelunarscape.com/blog/an-increasingly-active-sun
Better solution than using a plugin in this case, unless you want to something more fancy I guess as content plugins are run every time an article is loaded no matter if it's needed or not.
Another more advanced way to achieve this is with help of MooTools.
Include MooTools with in your application with:
jimport( 'joomla.html.html.behavior' );
JHtml::_('behavior.framework'); //MooTools core
JHtml::_('behavior.framework', true); //This is for MooTools more libraries
Next create a script that changes the css of the paragraph with id "myid":
$js = <<<EOD
window.addEvent('domready', function(){
$('myid').setStyle( 'border', '1px solid #000000')
});
EOD;
$document =& JFactory::getDocument();
$document->addScriptDeclaration($js);
Why use MooTools?
MooTools makes it possible to tweak the highlightning and even animate the highlight. It should also have better support for the older browsers.

CEWP to show images (HTML) works until I use grouping. Then I see the DIV tag

I'm fairly new to Share Point so forgive me if this is to easy for you guys, but I could not seem to find the answer anywhere and I am rather stumped.
I am currently trying to make a website to track if particular tasks go over their due date. I have a calculated column that leaves a DIV tag to the image of a red/yellow/green circle which is displayed by the javascript for a Content Editor Web Part (CEWP) made by Christophe on his site here:
http://blog.pathtosharepoint.com/2008/09/01/using-calculated-columns-to-write-html/
I was able to put his code into the CEWP and everything looks great when it is in a standard list.
But I want a web part version of this on the homepage for easy view. When I make the web part (of a view grouping by the image tag) and place on the main site all I see is the DIV tag! I made sure to put an identical CEWP on the homepage as well but i get as grouping:
+[columnName] : DIV>img title=blahblahblah>/DIV> (2)
Needles to say when I expand this it stays the same for all entries below
Any Ideas?
Thanks for your time :D
Nobody has responded, but I found the answer so hopefully this will save someone the hours of grief I had. This will seem ridiculous but just go with it.
In the calculated column instead of returning the type as text, return it as a currency. Sounds ridiculous BUT IT WORKS!!

Deleting elements using Watir

Does anyone know how to delete an element from the source using Watir? There doesn't seem to be a method for removing elements. Perhaps I'm missing something.
If you know JavaScript, you could execute any JavaScript code on the page.
Example:
browser.execute_script("some javascript code")
I am not a JavaScript ninja, but this question could help you: JavaScript: remove element by id.
Remove elements by css:
browser.execute_script("[...document.querySelectorAll('.some.class')].map(e => {e.parentNode.removeChild(e)})")
We can remove it with javascript. Here's an example to remove a breadcrumbs div element but it's id:
browser.execute_script("bd = document.getElementById('breadcrumbs'); bd.parentNode.removeChild(bd);")
The Purpose for Watir is to do web testing, which is to say drive the browser as if a user was interacting with it. That means doing the things a user could do, clicking on stuff, filling in input fields, etc. It also means being able to verify what is there on the screen that the user can see or interact with.
Since a user cannot delete elements, there is no means by which to do that using the tool.
If the application provides a way for users to 'remove' or 'delete' something, like closing a simulated window, removing a tab etc, then you need to do that by simulating what the user would do (usually clicking on some specific element) in order for that to happen.

Change appearence of page dynamically like twitter or tumblr

I'm trying to find tutorials or code to allow users to customise their page, just like twitter ,wordpress and tumblr do.
Could someone tell me what technology their using?
i'm a .net developer, but maybe they're using jquery?
Any help would be great.
Thanks
You can use javascript to change style sheets and the DOM
Question is a bit broad. To change the page you simply need to manipulate the DOM or change the CSS associated with the page's elements. This can be done any number of ways. E.g. you could write out a new CSS class dynamically, you could add new elements to the DOM itself or you could modify the existing attributes of the page. e.g. to set the background of the page you can do something like:
(assuming JQuery)
$("body").css('background-image','url(path/to/image)');
Hope that helps,
-fs

Basic bookmarklet help

I want to create a bookmarklet that sets the page to be editable, that is, to run this code:
javascript:document.body.contentEditable=true;
When I made a bookmark of that, I could see that the page becomes editable very briefly and then the whole thing is replaced with the word "true".
Bookmarklets have to evaluate to void for the browser stay on the same page. Just end it with a void(0):
javascript:document.body.contentEditable=true;void(0);
After a bit of random trial and error, I found that this worked:
javascript:(function() { document.body.contentEditable=true; })()
Are there any other ways?
Some sites suggest that you use document.designMode=’on’, but that doesn't work for me.
Regardless, your revised scripts works fine.

Resources