~nhoad/roland

ref: b91f46789159c99cba6d7857e8579e23e5ebebea roland/example_config.py -rw-r--r-- 5.2 KiB View raw
b91f4678 — Nathan Hoad This is obviously useful. 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
from urllib.parse import quote_plus
from roland import lazy, Mode

from urllib import parse as urlparse


home_page = 'https://google.com/'
search_page = 'https://www.google.com/search?q={}'


def close_backwards(browser):
    browser.close()
    browser.roland.prev_tab()


def buffer_close(browser):
    browsers = browser.filter_windows()
    for browser in browsers:
        browser.close()


def contextual_follow(browser):
    uri = browser.webview.get_uri()

    if not uri:
        return

    domain = urlparse.urlparse(browser.webview.get_uri()).netloc

    if domain.endswith('slack.com'):
        browser.follow(selector='a.channel_name>.overflow_ellipsis, a.im_name>.overflow_ellipsis, #message-input')
    else:
        browser.follow()


commands = {
    'i': lazy.set_mode(Mode.Insert),
    ':': lazy.prompt_command(),
    'Insert': lazy.set_mode(Mode.PassThrough),

    'b': lazy.select_window(),
    'C': buffer_close,
    'd': lazy.close(),
    'D': close_backwards,
    'o': lazy.open_or_search(),
    'O': lazy.open_modify(),
    't': lazy.open_or_search(new_window=True),
    'T': lazy.open_modify(new_window=True),
    'B': lazy.open_or_search(background=True),

    'r': lazy.reload(),
    'R': lazy.reload_bypass_cache(),

    'C-Up': lazy.zoom_in(),
    'C-Down': lazy.zoom_out(),
    '+': lazy.zoom_in(),
    '-': lazy.zoom_out(),
    '=': lazy.zoom_reset(),

    '/': lazy.search_page(forwards=True),
    '?': lazy.search_page(forwards=False),
    'n': lazy.next_search_result(forwards=True),
    'N': lazy.next_search_result(forwards=False),

    'C-o': lazy.back(),
    'C-i': lazy.forward(),

    'f': lazy.follow(),
    'F': lazy.follow(new_window=True),

    'C-f': lazy.javascript('window.scrollBy(0, window.innerHeight);'),
    'C-b': lazy.javascript('window.scrollBy(0, -window.innerHeight);'),
    'space': lazy.javascript('window.scrollBy(0, window.innerHeight);'),
    'S-space': lazy.javascript('window.scrollBy(0, -window.innerHeight);'),

    'C-c': lazy.stop(),
    'C-w': lazy.shell(),
    'C-q': lazy.quit(),

    'h': lazy.move(x=-1),
    'j': lazy.move(y=1),
    'k': lazy.move(y=-1),
    'l': lazy.move(x=1),

    'y': lambda browser: browser.roland.set_clipboard(browser.webview.get_uri()),
    'g': lazy.set_mode(Mode.SubCommand, 'g', {
        '^': lazy.select_window(1),
        '$': lazy.select_window(-1),
        '0': lazy.select_window(1),
        '1': lazy.select_window(1),
        '2': lazy.select_window(2),
        '3': lazy.select_window(3),
        '4': lazy.select_window(4),
        '5': lazy.select_window(5),
        '6': lazy.select_window(6),
        '7': lazy.select_window(7),
        '8': lazy.select_window(8),
        '9': lazy.select_window(9),
        't': lambda browser: browser.roland.next_tab(),
        'T': lambda browser: browser.roland.prev_tab(),
        'v': lambda browser: browser.toggle_tab_visibility(),
        'n': lazy.tab_bar_position('cycle'),
        'N': lazy.tab_bar_position('reverse-cycle'),
        'u': lazy.navigate_up(),
        'U': lazy.navigate_top(),
        'g': lazy.javascript('window.scrollTo(0, 0);'),
        'f': contextual_follow,
        'y': lazy.yank_links(),
    }),
    'u': lazy.undo_close(),
    'G': lazy.javascript('window.scrollBy(0, document.body.scrollHeight);'),
    'P': lazy.open_from_clipboard(),
}


def should_open_popup(uri):
    print("Yeah I'm going going to open this popup", uri)
    return True


def user_agent_choices():
    return [
        'user-agent 1',
        'user-agent 2',
        'user-agent 3',
    ]

# set this to what you want to use, by default use whatever WebKit uses.
default_user_agent = None

font = "ProFontIIx Nerd Font"

# put favicons in the tab bar.
show_favicons = True

# CSS style to use for input/label widgets.
style = '''
    * {
        border: none;
        box-shadow: none;
    }

    header, notebook, tab, entry, label {
        background: black;
        color: white;
    }

    .active-page
    {
        color: #01a252;
    }

    #InsertMode {
        color: #01a252;
    }

    #NormalMode {
        color: white;
    }

    #PassThroughMode {
        color: #01a0e4;
    }
'''

enable_disk_cache = True

# enable frame flattening to make pages with frames easier to navigate.
enable_frame_flattening = True

enable_webgl = True
enable_accelerated_2d_canvas = True

from gi.repository import Gdk
dpi = Gdk.Screen.get_default().props.resolution

# scale default zoom to account for the dpi, for my HiDPI monitor. Based on a default of 96 dpi.
default_zoom = dpi / 96.0 * 100

spell_checking_enabled = True
spell_checking_languages = ['en_AU']


def search_url(text):
    """Create custom searches based on what you've entered."""

    if text.startswith('twitter '):
        search = text[len('twitter '):]
        url = 'https://twitter.com/search?q={}&src=typd'
    elif text.startswith('reddit '):
        search = text[len('reddit '):]
        url = 'https://www.reddit.com/search?q={}'
    elif text.startswith('/r/'):
        return 'https://www.reddit.com{}'.format(text)
    elif text.startswith('nyaa '):
        search = text[len('nyaa '):]
        url = 'http://www.nyaa.se/?page=search&cats=1_0&filter=0&term={}'
    else:
        url = None

    if url is None:
        return
    else:
        return url.format(quote_plus(search))