Redefine tab as 4 spaces in Gitlab CE - gitlab

See this huge identations is painful (for me). Is there a way to set tab size to 4 spaces.
This picture is taken from local Gitlab CE server with minimal customization. I think tabsize 8 spaces is default.

Go to Settings -> Preferences -> Behavior and set Tab width

Yeah, gitlab uses browser CSS property tab-size which default value is 8.
There's a bug discussion about this here:
https://gitlab.com/gitlab-org/gitlab-ce/issues/2479
You can change gitlab CSS and you'll have what you want.

As of February 2021, this has not been addressed. One can check the current GitLab issue for progress, but in the meantime, this comment on the thread offers a solution via creating a UserScript via Greasemonkey / Tampermonkey with this script:
// ==UserScript==
// #name GitLab Tab Size
// #version 1
// #include https://gitlab.com/*
// #grant none
// ==/UserScript==
const TAB_SIZE = 2
window.addEventListener('load', function() {
const styleElement = document.createElement('style')
styleElement.innerHTML = `
.diff-content, pre.code {
-moz-tab-size: ${TAB_SIZE};
tab-size: ${TAB_SIZE};
}
`
document.head.appendChild(styleElement)
})
Credit to Brendan Gadd from that thread.

Related

Gitlab, how to change tabulation size on code review

While reviewing the code with gitlab merge request web page, tabulation is 8 spaces.
It makes the code difficult to read. How could I move it to 1 or 2 spaces ?
It seems to be impossible to achieve that by available GitLab settings, but this can be hacked using Greasemonkey/Tampermonkey browser extension:
// ==UserScript==
// #name Custom tab-width
// #version 1
// #grant none
// #include https://your.gitlab.server.com/*/diffs*
// ==/UserScript==
var style = document.createElement("style");
style.type = "text/css";
style.innerHTML = "span.line {tab-size:2; -moz-tab-size:2;}";
document.head.appendChild(style);
or by any other stylish-like extensions which allow you to attach any custom css rules to web pages:
span.line {tab-size:2; -moz-tab-size:2;}

Greasemonkey: leaving user configuration intact while updating

I've written a user script for Greasemonkey that requires some user configuration. To specify how they want the script to behave, a user needs to set a couple variables.
Right now, the script is set up like this:
// ==UserScript==
// #name My script
// #description A simplified example
// #include http://www.example.com/
// #version 0.0.1
// #updateURL https://www.example.com/myscript.meta.js
// ==/UserScript==
// Configuration
var config1 = "on";
var config2 = "off";
// Programs
[various functions that refer to the configuration variables]
I'd like to be able to update the script using Greasemonkey's automatic updates, while leaving the user's configuration lines intact. Basically, I don't want to force every user to redo their configuration after each update.
Is there a good method for updating a Greasemonkey userscript while leaving some configuration intact?
You may wish to utilise the greasemonkey functions GM_getValue() and GM_setValue(), which will store values that stay that way until they're changed again. The script can set values based on user needs, and get the value where required.
Specific GM functions require a special grant, in the metadata for the userscript:
// #grant GM_getValue
// #grant GM_setValue
Your code with the GM value functions may look like this:
var value = 18;
GM_setValue('dataName', value);
if (GM_getValue('dataName') == 18) ...
When you make updates to the script, instead of having the values set by GM_setValue overwritten, you could first check to see if they have been written:
var value = 18;
if (typeof GM_getValue('dataName') === 'undefined')
GM_setValue('dataName', value);
To enable users to control these settings, you could inject an HTML interface that shows the values of the database entries, and allows them to be set. This approach would then make such settings immune to script updates (as long as the script doesn't overwrite the database values).
Also, this question may also be a beneficial read.

How can I disable javascript for the page that's being opened?

I was up till 1 am last night trying to find an example of how to do this. My theory is that I'd write a function that would comment out all javascript.
The second option would be to add the url to the list of javascript settings.
Right now my extension is very simple:
function linkOnClick(info, tab) {
window.open(info.linkUrl)
}
chrome.contextMenus.create(
{title: "Load with no Javascript", contexts:["link"], onclick: linkOnClick});
This is my first extension and I'm kind of lost.
edit: let me know if I should also post the manifest.json.
edit: I can't mark this as solved for 2 days (why? who knows.), so I'll probably not remember to mark this as solved. So accept this as the official making: SOLVED.
chrome.contentSettings.javascript.set is the thing that disables javascript.
Here's the part that disables javascript.
(Google, here's what an actual example should look like):
chrome.contentSettings.javascript.set(
{'primaryPattern':AnyDomainName, /*this is a string with the domain*/
'setting': "block", /* block the domain. Can be switched to "allow" */
'scope':'regular'}, /*it's either regular or incognito*/
function(){
/*optional action you want to
take place AFTER something's been blocked'*/
});
Here's the script I used to import into my json script for my chrome extension.
var link=""
var pattern=""
function linkOnClick(info, tab) {
r = /:\/\/(.[^/]+)/;
link=info.linkUrl
pattern="http://"+link.match(r)[1]+"/*"
chrome.contentSettings.javascript.set(
{'primaryPattern':pattern,
'setting': "block",
'scope':'regular'},
function(){
window.open(link)
});
}
chrome.contextMenus.create({title: "Load with no Javascript", contexts:["link"], onclick: linkOnClick});
I couldn't tell how any of this worked by reading the developer.chrome.com page! They really need add complete working examples or allow a way for users to add examples. I can't even use it. The git hub link is what saved me.

Scriptish GM_getResourceText doesn't work

This works on Greasemonkey, but I don't know why it doesn't work on Scriptish:
// ==UserScript==
// #name myscript
// #namespace xxx
// #include http://*
// #version 1
// #grant GM_getResourceText
// #resource resourceName http://xxx.xxx/style.css
// ==/UserScript==
alert(GM_getResourceText('resourceName'))
The css file is actually downloaded, and console log says [myscript] not defined.
This has come up since Firefox update to version 30. Try to "enable #grant" in the settings of Scriptish. If you don't find this setting in your Scriptish options dialog, go to URL about:config and find the key extensions.scriptish.enableScriptGrant. If that doesn't work, go to scriptish download page and list all available versions. Version 0.1.12 works well with Firefox 30. Official latest version is 0.1.11.

Flash trace output in firefox, linux

I'm developing an applications which I've got running on a server on my linux desktop. Due to the shortcomings of Flash on Linux (read: too hard) I'm developing the (small) flash portion of the app in Windows, which means there's a lot of frustrating back and forth. Now I'm trying to capture the output of the flash portion using flash tracer and that is proving very difficult also. Is there any other way I could monitor the output of trace on linux? Thanks...
Hope this helps too (for the sake of google search i came from):
In order to do trace, you need the debugger version of Flash Player from
http://www.adobe.com/support/flashplayer/downloads.html (look for "debugger" version specifically - they are hard to spot on first look)
Then an mm.cfg file in your home containing
ErrorReportingEnable=1 TraceOutputFileEnable=1 MaxWarnings=50
And then you are good to go - restart the browser. When traces start to fill in, you will find the log file in
~/.macromedia/Flash_Player/Logs/flashlog.txt
Something like
tail ~/.macromedia/Flash_Player/Logs/flashlog.txt -f
Should suffice to follow the trace.
A different and mind-bogglingly simple workaround that I've used for years is to simply create an output module directly within the swf. All this means is a keyboard shortcut that attaches a MovieClip with a textfield. All my traces go to this textfield instead of (or in addition to) the output window. Over the years I've refined it of course, making the window draggable, resizable, etc. But I've never needed any other approach for simple logging, and it's 100% reliable and reusable across all platforms.
[EDIT - response to comment]
There's no alert quite like javascript's alert() function. But using an internal textfield is just this simple:
ACTIONSCRIPT 1 VERSION
(See notes at bottom)
/* import ExternalInterface package */
import flash.external.*;
/* Create a movieclip for the alert. Set an arbitrary (but very high) number for the depth
* since we want the alert in front of everything else.
*/
var alert = this.createEmptyMovieClip("alert", 32000);
/* Create the alert textfield */
var output_txt = alert.createTextField("output_txt", 1, 0, 0, 300, 200);
output_txt.background = true;
output_txt.backgroundColor = 0xEFEFEF;
output_txt.selectable = false;
/* Set up drag behaviour */
alert.onPress = function()
{
this.startDrag();
}
alert.onMouseUp = function()
{
stopDrag();
}
/* I was using a button to text EI. You don't need to. */
testEI_btn.onPress = function()
{
output_txt.text = (ExternalInterface.available);
}
Notes: This works fine for AS1, and will translate well into AS2 (best to use strong data-typing if doing so, but not strictly required). It should work in Flash Players 8-10. ExternalInterface was added in Flash 8, so it won't work in previous player versions.
ACTIONSCRIPT 3 VERSION
var output_txt:TextField = new TextField();
addChild(output_txt);
output_txt.text = (String(ExternalInterface.available));
If you want to beef it out a bit:
var alert:Sprite = new Sprite();
var output_txt:TextField = new TextField();
output_txt.background = true;
output_txt.backgroundColor = 0xEFEFEF;
output_txt.selectable = false;
output_txt.width = 300;
output_txt.height = 300;
alert.addChild(output_txt);
addChild(alert);
alert.addEventListener(MouseEvent.MOUSE_DOWN, drag);
alert.addEventListener(MouseEvent.MOUSE_UP, stopdrag);
output_txt.text = (String(ExternalInterface.available));
function drag(e:MouseEvent):void
{
var alert:Sprite = e.currentTarget as Sprite;
alert.startDrag();
}
function stopdrag(e:MouseEvent):void
{
var alert:Sprite = e.currentTarget as Sprite;
alert.stopDrag();
}
[/EDIT]
If you only need the trace output at runtime, you can use Firebug in Firefox and then use Flash.external.ExternalInterface to call the console.log() Javascript method provided by Firebug.
I've used that strategy multiple times to a large degree of success.
Thunderbolt is a great logging framework with built-in firebug support.
I use the flex compiler on linux to build actionscript files, [embed(source="file")] for all my assets including images and fonts, I find actionscript development on linux very developer friendly.
Then again, I'm most interested in that flash has become Unix Friendly as aposed to the other way around :)
To implement FlashTracer, head to the following address and be sure you have the latest file. http://www.sephiroth.it/firefox/flashtracer/ . Install it and restart the browser.
Head over to adobe and get the latest flash debugger. Download and install the firefox version as FlashTracer is a firefox addition.
Now that firefox has the latest flash debugger and flash tracer we need to locate mm.cfg
Location on PC: C:\Documents and Settings\username
Inside of mm.cfg should be:
ErrorReportingEnable=1
TraceOutputFileEnable=1
MaxWarnings=100 //Change to your own liking.
Once that is saved, open firefox, head to the flash tracer window by heading to tools > flash tracer. In the panel that pops up there is two icons in the bottom right corner, click the wrench and make sure the path is set to where your log file is being saved. Also check to see that flash tracer is turned on, there is a play/pause button at the bottom.
I currently use this implementation and hope that it works for you. Flash Tracer is a little old, but works with the newest versions of FireFox. I am using it with FireFox 3.0.10.

Resources