Injecting a custom stylesheet into a site via Chrome Devtools - css

Here's the plan: I'm trying to customize a site. I want to create and edit a CSS file locally (on my own text editor) and inject it into the page using the new Workspace and Filesystem features in DevTools.
These two features seem to work quite well, except they only allow you to map certain local files to network files.
I want to create a new file and inject that into the page, not modify an existing (loaded) stylesheet.
Anybody have any ideas?

U can use the chrome extentions for that...create an extention and everytime a page loads you can add that to it.I had done it earlier,modifying the contents of www.imdb.com for a extention of mine called Movie mapper,unfortunately Chrome store removed it after 1 yr.You want the code ? I can share

Related

multiple pages are overlapping in ngx-extended-pdf-viewer

I am using ngx-extended-pdf-viewer for my angular app and looks like multiple pdf pages are overlapping during viewing. here is my viewer code
<ngx-extended-pdf-viewer
*ngIf="isVisible"
[src]="pdfData"
useBrowserLocale="true"
[textLayer]="true"
[showPrintButton]="true"
[showDownloadButton]="true"
[showOpenFileButton]="false"
[showBookmarkButton]="false"
[showPresentationModeButton]="false"
height='90%'
[zoom]="'100%'">
</ngx-extended-pdf-viewer>
I tried setting stylesheets for page and viewer classes but no luck.
Sounds like you've got CSS rules interfering with the CSS rule of ngx-extended-pdf-viewer. Create a greenfield project to check if it's a general problem:
Open a terminal and navigate to the root folder of your project.
Run this command and accept the defaults:
ng add ngx-extended-pdf-viewer
Add the new component <app-example-pdf-viewer> to your <app-component> to display the PDF file.
Now you've got a working project that almost certainly does not suffer from your bug. Use the developer tools of your browser to compare the CSS code of the two projects to hunt down the bug.

How to reload single file in chrome developer tools

I'm working on a complicated site that has a lot of css files and js files that load on every page. I'm working on a single css using Chrome's developer tools. Once the css is mostly correct in developer tools, (Element tab, Styles side bar), the css is copied to a local css file and then uploaded to the web server. Since only a single css file has been modified it would be faster to reload a single css file instead of hard refreshing and reloading the entire site including images, js, and css, etc.
The site has an option to minify the css file and combine it with the other css files, creating one single very large css file. That option is turned off while in development mode. Adding a version number to the css file name isn't the trick I'm looking for.
Is it possible in Chrome Developer tools to click on a source file and refresh only that file?
This is a bit of a hack, but I think it'll work for your scenario.
When I initially load an example page, you can see three CSS requests:
I want to refresh the devsite-googler-buttons.css file, so I find it in my DOM Tree:
(Command+F on Mac or Control+F on Windows / Linux opens up that search panel at the bottom of the Elements panel... makes it easier to find stuff in a big DOM)
Right-click, select Edit as HTML, and then append a random query string to the end of the link:
And in the Network panel, you can see that the file was re-downloaded:
See also: Konrad's answer provides some handy code for automating this via a Snippet.
It might be handy, in your situation, to automate it a bit:
function reloadCSS() {
const links = document.getElementsByTagName('link');
Array.from(links)
.filter(link => link.rel.toLowerCase() === 'stylesheet' && link.href)
.forEach(link => {
const url = new URL(link.href, location.href);
url.searchParams.set('forceReload', Date.now());
link.href = url.href;
});
}
reloadCSS();
What this function does is it forces all CSS files to be reloaded by appending current time to their URLs.
You can modify it to target a specific file. You can run it from console, via DevTools 'snippets' functionality or make it into an extension.
If you don't mind refreshing the page, but don't want to re-download all resources, try the following.
Open the css file in a new tab. (You can right click css files from the Chrome developer tools and choose "open in new tab");
Hard-refresh this tab (ctrl/cmd + f5);
Soft-refresh the page (f5 or ctrl/cms + r).
According to me only Live editing is the only possible way what you are looking for I suppose. There is no way to refresh a single css file.

Trying to persist CSS changes to file on disk in Chrome Dev tools

I have just started exploring the possibility of saving changes made to a page and it's styling in Chrome Dev Tools on the fly.
I've followed this short video tutorial on mapping the project files on disk to the Dev Tools via the Sources tab. Everything works fine until around the 5:17 point where he selects an element in the Elements tab and makes several CSS style changes which automatically persist to the file on disk.
This doesn't work for me. The changes won't save to the file and when I refresh the page reverts to the original styles. I have checked to see if there is an asterisk beside the corresponding CSS file in the Sources panel, to denote changes have been made, but there is nothing there.
I have also tried the solution posted in this SO question but I don't see the link to the stylesheet after editing the style in the Elements tab that will redirect back to the file in the Sources tab allowing the changes to be saved.
Can anyone tell me what I am missing? Thanks!
You need to make sure you map your Workspace to a Network Resource to persist changes automatically. I have produced the steps below to get this working correctly.
Select the folder in Sources and click 'Add Folder to Workspace'
If you open up our stylesheet in Sources and go to the Elements panel to make changes, upon coming back you will see a separate instance of the stylesheet opened with pending changes. The reason is that Chrome doesn't know how to map the URL to the file on your system yet.
Select 'Map to Network Resource...'. You will notice that 'top' disappears.
Make a change in the Elements panel now. When you go back to the Sources panel, the changes will automatically be shown without requiring any explicit save.
You can see exactly what was done by going to the Workspaces section of the DevTools settings panel. We've added a local Workspace, and then mapping the URL, which in my case is on my computer and accessed with the file:// protocol, to the relative path on the system.

Is it possible to load a local css file to the browser for certain domains?

Using developer tools, I can amend a css file for a site I'm currently viewing in a browser.
I want to, effectively, do the same - but instead of amending the css file, loading a local css file, just for that particular domain.
Another way of phrasing it: "When any page of stackoverflow.com is loaded, load C:\test.css to the browser".
Yes, it's possible. Have a look at http://userstyles.org.
Userstyles.org offers CSS files for usage with the extension "Stylish", and Stylish recently announced that they are becoming evil (https://forum.userstyles.org/discussion/comment/109966/#Comment_109966) and can therefore not be used anymore.
One can use the styles with greasemonkey, but then the activation for various websites doesn't work anymore (the CSS is converted into a JS file and the list of sites where it should be applied onto is hardcoded inside an if-statement in that script). I.e. in order to use e.g. "dokuwiki highlight and full width" on a site using dokuwiki but not being http://dokuwiki.org, you have to edit that if-statement and reload.

Sharepoint MasterPages/Templates customization

I am pretty new to Sharepoint.
I need to customize some Sharepoint Masterpages (the background color, the font type and a few other css requeriments).
Considering I have available the following files: v4.master, default.master and two more pages which are content pages of default.master, plus the COREv4.css file.
I know I should create a copy of one of those master pages (I am not sure which tho) and customize it changing the CSS linked to it). The following questions come in regards of this:
1) The custom CSS file should be a modified copy of the COREv4.CSS or just another CSS file with the desired styles?
2) How do I create/link the customized CSS file for the modified page via Site Settings?. How/Where should I save the new file?.
3) As for the copy of v4.master, How do I load it to "replace" the original one for the site?.
4) The system is built upon Sharepoint 2010. That ensures that the page to have the modified CSS would be a v4.master copy only?.
Thank you for the insight as always.
**Update**
Hi,
I managed to solve the problem getting a general idea with the pdf manual provided, your suggestions and some extra steps I will describe briefly:
1) To place my custom css file I put it in the folder: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\3082\STYLES
2) I opened the site to be customized with Sharepoint Designer 2010.
3) I clicked on the option Main Pages/Master Pages, and selected the page to be v4.master page, copied and pasted it. Then I renamed it right clicking on it, selecting "Rename" and typed the new name, after doing that I right clicked one more and selected "Set page as main default page".
4) To edit the contents of the page I right clicked once more and selected the option "Edit content in advanced mode", right before the head tag ended I copied and pasted:
<SharePoint:CssRegistration name="customname.css" runat="server" After="core4.css"/>
Note that "customname.css" is my css file. Then I clicked on the floppy disk icon on the upper left side of the screen to save.
5) After doing that I used Chrome HTML/CSS Analyzer, inspecting the original (and now copied) master page to browse on the zones that needed customization in order to identify the class names/ids/element types that managed the styles to be changed. Once identified I only added to them the properties that required change, EG:
//Webparts Alternate Highlighted Rows
div#ctl00_MSO_ContentDiv table.ms-viewlsts tbody
tr.ms-alternatingstrong{ background-color:#F7FAF4 }
table.ms-listviewtable.ms-basictable tbody
tr.ms-alternatingstrong.ms-itmhover{ background-color:#F7FAF4 }
I mostly did this by myself by trial and error with Chrome Analyzer but I also helped the task using the Chart found here (http://sharepointexperience.com/csschart/csschart.html), tho at some point going thru it turned a bit tricky and I decided to do it by myself as I mentioned. In the process I repeatedly added more styles to the custom file and then overwrote it on the server location to refresh the page/pages to see how it was looking, this till the end of the process.
Thanks for your help, I hope this serves as a guide for anyone that needs it. If you have questions let me know.
You can create a new master page from the scratch or modify the existing one.
Please have a look at this link it may help you to get answers of your questions
http://www.rdacorp.com/wp-content/uploads/ASP-NET-Master-Pages-and-SharePoint.pdf
It's not advised to modify files of SharePoint.
Better to create new master page file, specify all CSS and script you want inside and install this with feature.
What version of SharePoint do you have? SharePoint 2010 Server or Foundation? Cause with server version you can brand your master page in a cool way:
see this link
Microsoft has a good introductory article on how you can/should do this.
http://office.microsoft.com/en-us/sharepoint-designer-help/customize-a-master-page-to-brand-your-site-HA102449505.aspx

Resources